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>You're talking about memory virtualization, which, unless you're developing an operating system, is nothing you have to care about, since it's transparent to user processes.</p> <p>It's true that the address your program sees, notepad.0073053, is not the same as the one that is physically on the hardware address pins on the processor. But, when the processor executes the call instruction, it doesn't translate the destination address by some magic and puts this translated addres into the program counter - the program counter will. after the call, hold 0x007353.</p> <p>The virtualization is done in the memory management unit (MMU), which you can think of as a separate piece of hardware between the actual processor and the ram. (Of course, they are on the same chip in modern processors, but there used to be separate MMUs long ago). Think of it this way:</p> <pre><code>+-----------------+ +----------------------+ +-----------------+ | CPU | | MMU lookup table | | RAM | +-----------------+ +----------------------+ +-----------------+ | call 73053 | 73053 | virtual | phys. | 63053 |00000 | | access 73053 on |----------&gt;| 10000-20000 | a0000 |---------&gt;|10000 | | the address bus | | 40000-50000 | 30000 | |20000 | +-----------------+ | 70000-80000 | 60000 | |30000 | +----------------------+ |40000 | |50000 | |60000 X | |70000 | |80000 | +-----------------+ </code></pre> <p>The MMU contains a lookup table - which virtual address range maps to which physical addres range. Whenever the processor accesses memory, it tells the mmu which virtual address to access; the MMU uses its lookup table to determine the actual physical address, and that's what it puts on the address bus. But, the processor doesn't care about this translation. What you see in Ollydbg is always the virtual address, never the physical one.</p> <p>The MMU entries are handled inside the operating system, which may rearrange them as it sees fit. For example, the OS may decide to need the RAM block at 60000 for something else, copy the block at 60000 to, for example, 20000, and update the MMU table. Your program won't notice anything of that - it still accesses the same virtual memory location, which is now at a different place in physical memory.</p> <pre><code>+-----------------+ +----------------------+ +-----------------+ | CPU | | MMU lookup table | | RAM | +-----------------+ +----------------------+ +-----------------+ | call 73053 | 73053 | virtual | phys. | 23053 |00000 | | access 73053 on |----------&gt;| 10000-20000 | a0000 |---------&gt;|10000 | | the address bus | | 40000-50000 | 30000 | |20000 X | +-----------------+ | 70000-80000 | 20000 | |30000 | +----------------------+ |40000 | |50000 | |60000 | |70000 | |80000 | +-----------------+ </code></pre> <p>If the operating system decides to page out a memory block to disk, it will clear the corresponding MMU entry. Now, when the processor tries to access that virtual memory, the MMU will generate a <code>page fault</code>, which tells the processor it can't access the memory.</p> <pre><code>+-----------------+ +----------------------+ +-----------------+ | CPU | | MMU lookup table | | RAM | +-----------------+ 73053 +----------------------+ +-----------------+ | call 73053 |----------&gt;| virtual | phys. | |00000 | | access 73053 on | | 10000-20000 | a0000 | |10000 | | the address bus | fault! | 40000-50000 | 30000 | |20000 | +-----------------+&lt;----------| 90000-a0000 | 40000 | |30000 | +----------------------+ |40000 | |50000 | |60000 | |70000 | |80000 | +-----------------+ </code></pre> <p>This page fault will make the processor call the page fault handler within the operating system. The OS keeps a list of which pages it has written to disk, finds a memory location that's currently unused, reads the required page from disk to that location, updates the MMU accordingly, then returns to the user program and re-executes the instruction that generated the page fault. The user program won't know anything about that (unless it tries hard to find out, for example by measuring the real time needed and comparing that to the expected time). In Windows, <code>perfmon</code>s <code>Ram/Page faults per second</code> counter will tell you how often that happened.</p> <p>(Actually, there are different kinds of page faults. Space in the MMU tables is quite limited, it normally doesn't map all of a user program's virtual addresses. When a page fault occurs, the OS first checks "Is that block of memory in RAM somewhere, with only the MMU entry missing?". If yes, the OS just generates the MMU entry and allows the program to continue. This is called a minor page fault, which is quite fast to handle; page faults that actually access the disk are called major page faults, and impact performance much more).</p>
5911
2014-07-22T02:08:12.817
<p>While running <code>notepad.exe</code> in Ollydbg, I got the following execution trace:</p> <pre><code>(CPU) ... [0x00C73689] CALL notepad.0073053 [0x00C7369E] PUSH 58 ... (Memory Map) Address Size Owner Section Contains Type Access Initial Mapped as ... 000FD000 00002000 Priv RW Guar RW 000FF000 00011000 stack of mai Priv RW Guar RW ... 00A90000 00001000 Priv RW RW 00C70000 00001000 notepad PE header Imag R RWE 00C71000 0000B000 notepad .text code,imports Imag R RWE ... </code></pre> <p>Under the virtual address system of windows operation system,</p> <p>Some address is not in the physical memory or RAM,</p> <ol> <li><p>Who will translate <code>CALL notepad.0073053</code> to <code>CALL [Real address 0x??????]</code>?</p></li> <li><p>When that address is file mapped, who will read that value from the disk in assembly language ?</p></li> </ol>
Virtual address translation in assembly language
|disassembly|
<blockquote> <p>pe-carv.py is script can be used to carve out portable executable files from a data stream.</p> </blockquote> <p><a href="http://hooked-on-mnemonics.blogspot.com/2013/01/pe-carvpy.html" rel="nofollow noreferrer">http://hooked-on-mnemonics.blogspot.com/2013/01/pe-carvpy.html</a></p> <blockquote> <p>It relies on pefile by Ero Carrera to parse the portable executable file format and calculate the file size. Since the script relies on the portable executable file format, data that is appended to the end of the file (overlay) will not be carved out.</p> <p>The algorithm of the script is simple. Search for the strings of the MZ header in a data stream, if found read from the address to the end of the file, then pass the buffer to pefile. If no exceptions are thrown by pefile then we have a valid portable executable file. If an error occurs, search for the next MZ header and then start the process again.</p> </blockquote>
5915
2014-07-22T11:57:49.877
<p>My exact question sounds like: Are there any tools for automated resources extraction such as driver or executable to the ready-to-go <code>.sys</code> or <code>.exe</code>/<code>.msi</code> ?</p> <p>I googled several ways, but they haven't solved my problem.</p> <ul> <li><strong><a href="http://hp.vector.co.jp/authors/VA003525/emysoft.htm#6" rel="nofollow">Exescope</a></strong> -- spoilt the output binary</li> <li><strong>7zip</strong> -- produced some rubbish(i.e. I can not figure out how to use it to achieve the goal)</li> <li><strong><a href="http://www.legroom.net/software/uniextract" rel="nofollow">Universal Extractor</a></strong> -- same as 7zip</li> </ul> <p>Any tips will be appreciated.</p>
Extract driver from PE
|binary-analysis|pe|
<p>This is self-modifying code. The garbage instructions that you see will be altered dynamically, this way:</p> <pre><code>seg000:00000000 mov edx, 61666A1Fh seg000:00000005 fincstp seg000:00000007 fnstenv byte ptr [esp-0Ch] seg000:0000000B pop esi ; EIP </code></pre> <p>Now esi points to the location of the <code>fincstp</code> instruction (<code>00000005</code>).</p> <pre><code>seg000:0000000C sub ecx, ecx seg000:0000000E mov cl, 33h ; loop counter seg000:00000010 xor [esi+12h], edx seg000:00000013 add edx, [esi+12h] ;sliding key </code></pre> <p><code>esi+12</code> (<code>00000017</code>) is being altered, turning this:</p> <pre><code>seg000:00000016 xor ecx, 0FFFFFF96h seg000:00000019 test [ecx+esi*8+957C08Fh], dl </code></pre> <p>in to this:</p> <pre><code>seg000:00000016 sub esi, 0FFFFFFFCh seg000:00000019 loop near ptr 00000010 </code></pre> <p><em>i.e.</em> <code>esi = esi + 4</code>, now it's <code>00000009</code> (and, then, <code>0x0000000d</code>, <code>0x00000011</code>, ...), and the loop continues via the value in <code>ecx</code>. It's a shellcode-style decryptor. More detailed descriptions of this technique can be found <a href="http://pferrie.host22.com/papers/shellcode1.pptx">here</a> and <a href="http://pferrie.host22.com/papers/shellcode2.pptx">here</a>.</p>
5916
2014-07-22T13:19:08.853
<p>I see a lot of in and out instruction in IDA. I know what those are supposed to do, but I do not know how to treat them and I'm making no advancements in understanding the code.</p> <p>Short example: First instructions of my current assignment are:</p> <pre><code>seg000:00000000 mov edx, 61666A1Fh seg000:00000005 fincstp seg000:00000007 fnstenv byte ptr [esp-0Ch] seg000:0000000B pop esi ; EIP seg000:0000000C sub ecx, ecx seg000:0000000E mov cl, 33h ; '3' seg000:00000010 xor [esi+12h], edx seg000:00000013 add edx, [esi+12h] ; seg000:00000016 xor ecx, 0FFFFFF96h seg000:00000019 test [ecx+esi*8+957C08Fh], dl seg000:00000020 push eax ; ?????? seg000:00000021 mov bl, 0DEh ; '¦' seg000:00000023 in al, dx seg000:00000024 popa seg000:00000025 loope near ptr 0FFFFFFACh </code></pre> <p>I'm a bit lost at <code>05h</code>-<code>0Bh</code> as it's the first time I encounter FPU instructions, but I think that <code>ESI</code> should point to the where <code>EIP</code> is pointing to. </p> <p>My main question is regarding <code>23h</code>.</p> <pre><code>in al, dx </code></pre> <p>Should load a in <code>AL</code> a byte from port <code>6A1Fh</code>? Is this relevant in any way or is code like this supposed to make my work harder or hide something? Maybe it's encrypted and at some point some decrypting algorithm will kick in. Or maybe that shouldn't be viewed as code? </p>
in / out instructions - how should I treat this?
|binary-analysis|
<p><code>RtlCreateUserStack()</code> creates the stack on thread creation (And every process has the main thread). Or more generally: The Windows PE loader. What is the PE loader? That thing that creates a process out of an executable file on disk (or adds that executable file to a process in case of DLLs) </p> <p>Your other question is why, by the time Olly breaks, there already are values on the stack.<br> That is because your <code>main()</code> entrypoint is not the first thing that will be executed in the process. Before <code>main()</code> there is a lot of internal CRT setup, maybe even setting up global classes, ...</p> <p>But even before any code of your executable is executed the DLLs still need to do some initalization of their own.</p> <p>As you use OllyDbg, go to <kbd>Options</kbd>-><kbd>Debugging</kbd>-><kbd>Start</kbd> and play around with that to get a feeling about what needs to be done before your code runs.</p>
5923
2014-07-23T01:49:02.503
<p>When I start <code>notepad.exe</code> with ollydbg in Windows XP, the initial register was <code>esp:7FFC4</code> and <code>ebp:7FFF0</code>.</p> <pre><code>stack ... 0007FFC4 7C817067 kernel32.7C817067 &lt;--- ESP 0007FFC8 7C940208 ntdll.7C940208 0007FFCC FFFFFFFF 0007FFD0 7FFDB000 0007FFD4 80546BFD 0007FFD8 0007FFC8 0007FFDC 81D22DA8 0007FFE0 FFFFFFFF &lt;--- EBP 0007FFE4 7C839AC0 kernel32.7C839AC0 0007FFE8 7C817070 kernel32.7C817070 0007FFEC 00000000 0007FFF0 00000000 0007FFF4 00000000 0007FFF8 0100739D notepad.&lt;ModuleEntryPoint&gt; 0007FFFC 00000000 ... </code></pre> <p>I first guessed the initial stack was empty, but by the process argument (<em>e.g.</em>, <code>argc</code>, <code>argv</code>), I thought it can have some values.</p> <ol> <li>what is meaning of the initial stack between <code>EBP</code> and <code>ESP</code>?</li> <li>the stack <code>ESP</code> can be lower than <code>7FFE0</code> (over than as value) while <code>notepad.exe</code> is running ? In other words, can esp point at <code>0007FFF8</code>?</li> </ol>
Who does construct the stack on process creation in Windows?
|windows|x86|stack-variables|
<p>Use <code>ent</code>: <a href="https://www.fourmilab.ch/random/" rel="nofollow noreferrer">https://www.fourmilab.ch/random/</a> to run statistical tests checking for randomness.</p> <pre><code>$ cat 1-gb-file.img | ent Entropy = 7.999998 bits per byte. Optimum compression would reduce the size of this 100000000 byte file by 0 percent. Chi square distribution for 100000000 samples is 249.38, and randomly would exceed this value 58.75 percent of the times. Arithmetic mean value of data bytes is 127.4928 (127.5 = random). Monte Carlo value for Pi is 3.141514686 (error 0.00 percent). Serial correlation coefficient is -0.000094 (totally uncorrelated = 0.0). </code></pre>
5926
2014-07-23T10:24:35.413
<p>I've heard of <a href="http://gynvael.coldwind.pl/?id=158">tools</a> that could be used to graph entropy of a file. Is there a graphical Linux program that I could use for this job that would let me conveniently explore which blocks of a file have certain entropy patterns that could suggest compressed or encrypted data?</p>
What Linux software can I use to explore entropy of a file?
|binary-analysis|
<p>In addition to what others have already mentioned with respect to Compiler Optimizations, there is another possibility. At times, malwares can perform control flow obfuscations by making use of a lot of opaque predicates (in this case, unconditional jumps).</p> <p>In fact, if you perform an instruction trace using a pintool (DBI) on a malware, at times you will observe a lot of jmp instructions executed in sequence. You can observe these type of subroutines in malwares which make use of polymorphic engines. It can help deter reverse engineering as it alters the control flow while stepping through the code.</p>
5930
2014-07-24T10:39:50.080
<p>I have noticed many times whilst disassembling executables that often the compiler will produce jumps to other unconditional jumps, rather than simply jumping to the final destination. For example:</p> <p><img src="https://i.stack.imgur.com/rlCkX.png" alt="enter image description here"></p> <p>Notice instead of <code>jmp 0x100001634</code> it would have written <code>jmp 0x100001681</code> and skipped the two other jumps in between. Is there a particular reason for not doing so?</p>
Why jump to unconditional jumps?
|disassembly|assembly|compilers|
<p>Have you tried manually loading the Hex-Rays plugin before loading your plugin?</p> <p>For example:</p> <pre><code>#include &lt;idc.idc&gt; static main() { Wait(); Message("Hello world from IDC!\n"); RunPlugin("hexrays",0); RunPlugin("REcompile vs Hexrays",0); //Exit(0); } </code></pre>
5931
2014-07-24T11:15:50.213
<p>I overcame recent issues with a redefinition and finished my Plugin.</p> <p>In short this plugin uses Hex-Rays Decompiler to decompile a given file, analyzes properties of the pseudocode and then appends the results to a <code>.csv</code></p> <p>Now I tried to use this in batch mode, but was stumped as the following happened:</p> <p>Cmd input to call IDA:</p> <pre><code>idaw -A -c -Srecompile.idc input_file </code></pre> <p>The <code>recompile.idc</code> file:</p> <pre><code>#include &lt;idc.idc&gt; static main() { Wait(); Message("Hello world from IDC!\n"); RunPlugin("REcompile vs Hexrays",0); //Exit(0); } </code></pre> <p>I obviously need to <code>Wait()</code> for Auto-Analysis. <code>Exit()</code> is commented since it's for use when this is all fixed.</p> <p>Now i do get the following output on execution:</p> <pre><code>The initial autoanalysis has been finished. Hello world from IDC! LoadLibrary(C:\Program Files (x86)\IDA\plugins\REcompile vs Hexrays.plw) error: Das angegebene Modul wurde nicht gefunden. C:\Program Files (x86)\IDA\plugins\REcompile vs Hexrays.plw: can't load file Hex-Rays Decompiler plugin has been loaded (v1.6.0.111005) Hex-rays version 1.6.0.111005 has been detected, REcompile vs Hexrays ready to use </code></pre> <p>As you can see the script is executed before the plugins are loaded. I assume this is the reason why I get the <code>LoadLibrary</code> Error.</p> <p>If you have any other input or experience with plugin batch execution i'd be happy to hear from you.</p> <p>Greetings, Viktor</p>
Ida Plugin Batch analysis issue.
|ida|ida-plugin|idapro-sdk|
<p>DDRAW is an object based interface. DirectDrawCreate creates DDRAW interface object (based on GUID provided as paramter). Regarding black area, most probably rendering part uses internally smaller resolution. Could you share the game's name?</p>
5935
2014-07-24T21:39:22.400
<p>I have an old game that I am wanting to increase the resolution on. The problem is that the game is ancient and was written using <code>DDRAW</code> and <code>GDI</code> .A few things are weird with this application, First starting from the entry point all the program does is create the process. secondly all the other code is indeed executed just I can't break over it (Making reversing a very slow process).</p> <p>Has anyone tried to reverse a <code>DDraw</code> application?</p> <p>I so far, have it to where I have expanded the resolution in such, that the application is still showing the default resolution just pushed to the left top corner and everything is still the 640x480 and is surrounded by black BUT the cool thing is I can click out of the 640x480 in the black area and click on objects and move to them. Would anyone know how to possibly resolve this?</p> <p>Another thing, it doesn't seem to matter what kind of break point I set in this(outside of EP) area of code the program never breaks there. Is there something I am missing here?</p> <p>I can try to come up with a picture as an example if that would help ; if no one understands how I am describing resolution.</p> <p>Also, I only see a call for <code>DirectDrawCreate</code> and it looks like it would point to an object or window but I cant tell entirely cause I cant break here.</p>
Reversing DDRAW application
|windows|ollydbg|interoperability|
<p>You can try using javasnoop (<a href="https://code.google.com/p/javasnoop/" rel="nofollow">https://code.google.com/p/javasnoop/</a>) to accomplish something similar.</p> <p>Here's a tutorial for using it -</p> <p><a href="http://resources.infosecinstitute.com/hacking-java-applications-using-javasnoop/" rel="nofollow">http://resources.infosecinstitute.com/hacking-java-applications-using-javasnoop/</a></p>
5941
2014-07-26T18:15:54.497
<p>Okay. So I've just come up with the most amazing program for java developers and reverse-engineerers and I was wondering if something like the following program already exists:</p> <p>What I'm thinking of is like a middle-ground between something like <a href="http://dirty-joe.com/">DirtyJOE</a> and a Java Decompiler.</p> <p>I already know that:</p> <ul> <li>It's possible to inject and manipulate code in a compiled class using <a href="http://asm.ow2.org">ASM</a></li> <li>You can decompile an unobfuscated jar into a readable and understandable state</li> <li>It's practical to explore and edit a class using a GUI because DirtyJOE can do that amazingly well</li> </ul> <p>So is there some sort of program that can show me a decompiled class and allow me to manipulate/inject into different parts of it individually?</p> <p>For example, I would like replace one method with my own or change a field's access within a compiled class file.</p> <p>So basically I'm looking for a frontend for ASM built with an interface based on decompiled source code.</p> <p>Does this exist? If not, what's the closest thing I'm going to get to it?</p>
GUI for transforming Java Bytecode based on decompiled source?
|disassembly|decompilation|java|byte-code|jar|
<p>I downloaded the archive you referenced and the first thing I noticed was that the firmware files are very heavy in the 0x80 - 0xff range. Inverting each byte resulted in a much nicer byte distribution and looked like it had some structure but still not quite right. I assume that since they went as far as inverting the bytes, they might have done some bit-manipulation such as XOR.</p> <p>Since this file is a firmware update, there is usually a header or a footer. It looks like there is a header of offsets or something, but nothing made sense. Scrolling further through the file, around byte 35000, there appears to be a block of structured data, followed by a block of 0xff and then a 16-byte "footer":</p> <pre><code>003F1F0: 84 95 74 64 B4 63 13 14 00 00 00 00 3C DC C5 6C ..td.c......&lt;... </code></pre> <p>The first 8 bytes look like a good place to start. Going through a few common XOR strategies resulted in nothing. Then I noticed that these bytes have a low nibble of 3, 4 or 5 which would place them in the printable ASCII range. So swap the nibbles of each byte (aka rotate left 4 bits) ... :</p> <pre><code>003F1F0: 48 59 47 46 4B 36 31 41 00 00 00 00 C3 CD 5C C6 HYGFK61A........ </code></pre> <p>Bingo! Since the firmware updater window title is "HY USB Firmware Downloader", I think this is a winner. Loading the resulting file into IDA, Cortex M-0 Thumb 2 settings, and sure enough, we have valid code starting at offset 0x0120 and ASCII string block at offset 0x32121.</p> <p>Summary: Decode the .bin files by processing each byte as:</p> <pre><code>rotate left 4 bits and invert: c = (((c &amp; 0x0f) &lt;&lt; 4) | ((c &amp; 0xf0) &gt;&gt; 4)) ^ 0xff </code></pre>
5945
2014-07-27T19:00:28.643
<p>I'm planning to buy my first mechanical keyboard, a KBT Poker II, and apart from the physical characteristics of it, another thing that caught my attention is that it sports reflashable firmware! Reversing and hacking on the firmware would be a fun personal project. (Unfortunately, the flasher is windows-only... I'm not sure how to deal with that, but that's another question.)</p> <p>Sadly though, when I tried poking around with the firmware files I couldn't make sense of it--I tried running a few Thumb disassemblers (as well as hacking up my own to learn more about Thumb) on parts of it that would seem to contain code (upon hexdump inspection), but they all came up with garbage instruction as far as a I could tell--certainly no function prologues/epilogues, and a lot of crazy immediates all over the place as well as absurd amounts of shifts and LDMs.</p> <p>Some technical information on the hardware inside the keyboard: it's built around a <a href="http://www.nuvoton.com/hq/products/microcontrollers/arm-cortex-m0-mcus/nuc120-122-123-220-usb-series/nuc122sc1an/">Nuvoton NUC122SC1AN</a>, which features a Cortex-M0 CPU. The firmware files in question are supplied in an attachment to <a href="http://geekhack.org/index.php?topic=50245.0">this forum post</a> (by the keyboard manufacturer).</p> <p>What I <em>have</em> found, however, is the interrupt table located at <code>$0000</code>--its length exactly matches that of the one documented on ARM's website, including IRQs 0..31. However, another oddity here is that they all point to interrupts in the high memory--<code>$ffff_fff00</code> and such. This area isn't included in the memory map of the NUC122, and ARM's spec has it as "reserved", but I'm guessing it might be mapped to some internal memory containing the chip-flashing-receiving code and such, and that the interrupts either trampoline to user (firmware) code or the table gets overwritten with interrupt handlers supplied by the firmware. Anyway, I'd probably be able to figure that out once I have some code to look at.</p> <p>I've tried binwalking the files, and it came up empty for all of them.</p> <p>To be clear, <strong>what I'm looking for</strong> in an answer here is guidance to where I find the actual executable code in one of the firmware files above (supplied by the manufacturer itself, so there should be no legal isues here), because I'm really not getting it. I should add that I'm relatively new to the world of reversing. Thanks!</p>
Finding the actual Thumb code in firmware
|disassembly|binary-analysis|firmware|
<p>An alternative approach would be to use the browser tools or a browser extension, such as Google Developer Tools for Chrome or Web Console for Firefox. These tools will show you the entire request, response, and body of all network traffic and timeline of when connections are made. In Chrome, you can even edit the page content and review how it affects the page. These are very powerful tools for reverse engineering the DOM and request structure. </p>
5948
2014-07-28T05:30:06.883
<p>I want to reverse engineer an application using HTTPS to communicate.</p> <p>I need a tool that performs a man in the middle attack and send it's own SSL certificate to the application, so I can decrypt the HTTPS connection it makes by passing the RSA private key to WireShark.</p> <p>By the way, I have heard about a tool called <a href="https://www.stunnel.org/index.html" rel="nofollow"><code>stunnel</code></a>, but the documentations I found about how to configure it just confused me. :|</p>
Using Stunnel to packet capture HTTPS connection
|sniffing|wireshark|https-protocol|
<p>While others have already provided some answers, I would like to add some additional points.</p> <p>You could code a pintool (DBI) which logs all the API calls. You could add some filters in your pintool to reduce the amount of API calls you log. Using a pintool has an advantage since anti debugging techniques used by malwares would not have an effect on it. Of course, we are assuming that the malware is not trying to protect itself from DBI frameworks. However, if you set breakpoints on LoadLibrary and GetProcAddress to see which libraries are loaded dynamically and which function addresses are resolved, you could be effected by anti debugging techniques used by the malware. Before you hit the breakpoint, the malware would have already discovered that it is being debugged and alter the program flow.</p> <p>I would suggest you not to conclude the functionality of a malware only by looking at the API names imported from different modules. A sequence of API calls can sometimes indicate malicious activity. For instance,</p> <pre><code>CreateProcessW VirtualAllocEx WriteProcessMemory WriteProcessMemory GetThreadContext SetThreadContext ResumeThread </code></pre> <p>Now, you could see these API names imported from kernel32.dll when you open the binary in a software like CFF explorer, however to conclude the usage of these APIs, an API trace would help. In this case, it is a standard method used by several binaries to perform code injection into the address space of another process.</p>
5949
2014-07-28T05:37:13.850
<p>I want to know how to find the functions which is interesting in malware tools. For example, I have a sample of unknown virus (this sample is <code>lab01-01.exe</code> in the book practical malware analysis <code>lab1-01.dll</code>). It is not packed.</p> <p>I am supposed to find out what does this malware by knowing the imported DLLs and the functions it uses. Here are the imported functions in the executable file <code>lab01-01.exe</code>:</p> <pre><code>KERNEL32.dll : CloseHandle UnmapViewOfFile IsBadReadPtr MapViewOfFile CreateFileMappingA CreateFileA FindClose FindNextFileA FindFirstFileA CopyFileA </code></pre> <p>And from <code>MSVCRT.dll</code>:</p> <pre><code>_getmainards _p_initenv _p_commode _p_fmode _set_apps_typr _setusermatherr _adjust_fdiv _controlfp _except_handler3 _exit _initterm _stricmp _XcptFilter exit malloc </code></pre> <p>But, I didn't find any function imported from <code>lab01-01.dll</code>. </p> <p>I also want to know why, although the book mentioned that both the executable file and DLL are related (it should be imported).</p>
How to figure out which imported function(s) in a virus determine its behaviour?
|windows|malware|static-analysis|dll|pe|
<p>This is compiler dependent - the compiler may place the vtable wherever it wants to, as long as it does it consistently. However, in most cases, the vtable pointer is the first element (at offset 0) of the generated structure.</p> <pre><code>class test { int a; int b; test() { ...; } ~test() { ...; } void somefunc() { ...; } int c; } </code></pre> <p>would use this memory layout for the class:</p> <pre><code>+----------------+ +--------------+ | vtable | ------------&gt; | test | +----------------+ +--------------+ | a | | ~test | +----------------+ +--------------+ | b | | somefunc | +----------------+ +--------------+ | c | +----------------+ </code></pre> <p>so (assuming pointers and integers are all 4 bytes), the vtable is at offset 0, a at 4, b at 8 and c at 12.</p> <p>Note that not all compilers use this convention. For example, the Watcom C++ 386 compiler didn't use a vtable at all, but mixed the function pointers with data. (I know this case because i once disassembled a game that was compiled with Watcom 20 years ago. Not that i expect you to ever see this kind of layout in a modern compiler, just to provide an example that it can be different):</p> <pre><code>+----------------+ | test | +----------------+ | ~test | +----------------+ | a | +----------------+ | b | +----------------+ | somefunc | +----------------+ | c | +----------------+ </code></pre> <p>The entries at offset 0 and 4 (again, assuming 4 byte integers/pointers) are the parameterless constructor and destructor function of the class, the rest is a mix of variables and methods in the order they appear in the class definition. Of course, this is horribly inefficient, because the compiler has to initialize every class method whenever an object is instantiated, instead of just setting one pointer to the vtable.</p> <p>TL;DR: In most cases, the vtable pointer is the first element of the class structure, but you really need to know which compiler was used and which conventions this compiler has.</p> <p>Another thing - you talk about a "vtable overflow" in your original post. Your "normal" exploit doesn't overflow a vtable; the vtables are pre-initialized when your program starts, and (normally) never ever change. To write an exploit, you would either:</p> <ol> <li>use a buffer overflow to modify a function pointer in a vtable, so the next time the class method gets called, your code is executed instead</li> <li>use a buffer overflow to modify the vtable pointer of a class instance, so the next time this class instance executes a method, your vtable is used instead of the other one.</li> </ol> <p>As vtables normally don't change, and may even be placed in a read-only memory segment by the compiler, your normal exploit ignores 1. and uses 2.</p>
5956
2014-07-28T12:26:34.920
<p>Actually, I am trying to learn a little about vtable overflows. So, my learning documents state the following: </p> <blockquote> <p>The main point to realize is that whenever we declare a C++ class with virtual methods, the pool of memory where it exists (the heap, the stack, etc.) now contains a pointer to a function pointer table which will eventually be used to call the function. In the event of an overflow, we can overwrite this pointer value so that our code will be called the next time a virtual method is called.</p> </blockquote> <p>So, my question is, how do I find the location of the vtable pointer ? </p> <p>I mean, do I have to search through PEB like when I am trying to find the base address from some modules. Or, is this specific for each situation ?</p>
How to find the location of the vtable?
|debuggers|c++|vtables|
<p>"Extremely unlikely and uncommon" sounds exactly like something malware would try/strive for. </p> <p>Using normal WinAPI functions, as a distraction for the reverser or a time-wasting mechanism against an emulator, in malware packers is common <a href="http://www.mcafee.com/au/resources/reports/rp-packer-layers-rogue-antivirus-programs.pdf" rel="nofollow"></a>.<br> There is no reason for not using msvcrt.dll functions (However one cannot count on Redistributable Packs for Visual Studio X being installed so the presence of msvcrt90.dll and similar is a flag against it being malware), so the presence of msvcrt* is not reliable at all.</p> <p>Entry-point signature, Rich signature or the debug directory would be better choices.</p> <p>Just quickly: Those with a D are the debug versions. </p>
5972
2014-07-29T15:30:35.310
<p>While viewing the PE headers and imported functions of some programs designed with visual C. I found that they all include one of these functions:</p> <ul> <li><code>MSVCRT.DLL</code></li> <li><code>MSVCR80.DLL</code></li> <li><code>MSVCR90.DLL</code></li> <li><code>MSVCR100D.DLL</code></li> <li><code>MSVCRT20.DLL</code></li> <li><code>MSVCRT40.DLL</code></li> <li>And other DLLs which starts with the MSVC prefix.</li> </ul> <p>Does this mean that any program (even malware) that imports any of these functions must be compiled by MSVC ?</p>
Does MSVCXXX.dll means that the PE file is compiled by Microsoft Visual C?
|disassembly|c++|c|pe|
<p>There are a couple of possiblities here.</p> <p>One possibility is that the relocation table has been truncated, so you see only the first page of relocation items (the table is an array of items on a per-page basis).</p> <p>Another possiblity is that the file doesn't support ASLR (perhaps intentionally, or perhaps it is assumed to not exist) so the relocation table isn't parsed. This would allow the address at 0x40be04 to execute even in the absence of a relocation item, because the image will never be loaded to another address.</p> <p>Further, the disassembly itself looks strange, as though the file is obfuscated. If so, then it is quite possible that the author of the obfuscator does not take ASLR into account, and so did not bother to add relocation items for the relevant jump.</p>
5978
2014-07-29T18:13:20.037
<p>I'm analyzing entries in the relocation section of a binary. In particular, I want to know if all the targets of jumps have a corresponding entry in the relocation section. The screenshot shows the relocation section entries of the binary I'm analyzing, to the left, as well as the assembly code of the binary showing only the jump instructions, to the right. </p> <p><img src="https://i.stack.imgur.com/bwKfF.png" alt="Relocation section and disassembly of binary"></p> <p>From what I understand, the first instruction in the assembly code at address 0x40be04 (jmp *0x4f422c) should have an entry in the relocation section. However, the last entry in the relocation section is for address 0x401fee.</p> <p>Why don't some addresses have an entry in the relocation section? Am I misunderstanding something in my analysis?</p> <p>P.S: The screenshot shows the binary disassembled using objdump on cygwin. The relocation section entries were generated using PE-Parser (<a href="https://github.com/trailofbits/pe-parse" rel="nofollow noreferrer">https://github.com/trailofbits/pe-parse</a>)</p>
Missing addresses from relocation section of ASLR enabled PE binary
|binary-analysis|binary-format|
<p>Basically, distinguish between values, addresses and instruction is the role of a <strong>type recovery system</strong>.</p> <p>There is an excellent seminal paper from Alan Mycroft about a technique called <a href="http://www.cl.cam.ac.uk/~am21/papers/esop99.ps.gz" rel="nofollow">type-based decompilation</a> (ESOP'99) which might give you some ideas on how to do.</p> <p>Another, more recent, paper describes the technique that is currently used in the <a href="http://users.ece.cmu.edu/~ejschwar/pres/usenix13.pdf" rel="nofollow">Phoenix decompiler</a> which is called: <a href="http://users.ece.cmu.edu/~aavgerin/papers/tie-ndss-2011.pdf" rel="nofollow">TIE: Principled Reverse Engineering of Types in Binary Programs</a> (NDSS'11) written by people from CMU and that give an in-depth of the technique they use.</p> <p>Apart from that, the reconstruction of the <em>shape</em> of the types (array, struct, etc.) can be done by using the <a href="https://research.cs.wisc.edu/wpis/papers/vmcai07.invited.pdf" rel="nofollow">DIVINE technique</a> (VMCAI'07) by Reps and Balakrishnan. A more extensive <a href="http://pages.cs.wisc.edu/~bgogul/Research/Journal/toplas10.pdf" rel="nofollow">journal paper</a> (TOPLAS'10) has been also published by both authors that gather all their work about the topic.</p> <p>Still, there are a lot of other works on this domain, but I believe the papers I cited above to be, more or less, the current trend in the 'type-recovery' domain.</p>
5984
2014-07-31T01:28:02.850
<p>So basically I am writing some code to do analysis work on disassembled assembly code.</p> <p>I am trapped in this issue for a while, here is an simple example of a disassembled asm code by objdump, basically all the address symbols have been translated into concrete value.</p> <pre><code>1. mov 0x8408080, %eax 2. .... 3. call *%eax </code></pre> <p>So basically for the above example, it is easy to determine that <code>0x8408080</code> used in line 1 is an address of code, and I know it is relatively easy to heuristically consider all the value falling into the range of <code>.text section</code> as a pointer. </p> <p>However, how to use static analysis to automatically identify this issue? (I want to write a tool to analyze large amount of code as accurate as possible)</p> <p>I know somehow I should use <strong>constant propagation</strong> to forwardly do the analysis, but basically as I am new to program analysis, I just don't know actually where to start..</p> <p>Does anyone have experiences like this? Or is there any implemented tools I can look for help..?</p>
How to do static analysis to identify pointer from concrete value in assembly?
|disassembly|assembly|x86|static-analysis|
<p>For Firefox (i.e. Gecko) and Chrome (i.e. Blink) you can just look in the source code:</p> <p>Searching the Firefox codebase for <code>getCurrentPosition</code> yields the source file <a href="http://dxr.mozilla.org/mozilla-central/source/dom/src/geolocation/nsGeolocation.cpp#697" rel="nofollow">nsGeolocation.cpp</a>. As you see in the linked source line, it creates an instance of a geolocation provider. Assuming Firefox for Desktop, there is only the <a href="http://dxr.mozilla.org/mozilla-central/source/dom/system/NetworkGeolocationProvider.js" rel="nofollow">NetworkGeolocationProvider</a> (FirefoxOS may also use GPS).</p> <p>In essence, Gecko opens an XMLHttpRequest to the URL specified in <code>about:config</code> as <code>geo.wifi.uri</code>. Per default this is <code>https://www.googleapis.com/geolocation/v1/geolocate?key=%GOOGLE_API_KEY%</code>.</p> <p>Blink performs its http request in <a href="https://code.google.com/p/chromium/codesearch#chromium/src/content/browser/geolocation/network_location_request.cc" rel="nofollow">network_location_request.cc</a>, with the same API endpoint defined as in Firefox (cf. <a href="https://code.google.com/p/chromium/codesearch#chromium/src/content/browser/geolocation/location_arbitrator_impl.cc&amp;rcl=1407097784&amp;l=43" rel="nofollow">location_arbitrator_impl.cc</a>).</p> <p>(NB: I looked at Gecko HG revision a4f779bd7cc2 and Blink SVN revision 287303)</p>
5993
2014-07-31T18:45:55.150
<p>I've been trying to figure how a html5 browser like chrome or firefox performs geolocation under the hood but I'm running into some difficulties.</p> <h2>Difficulties</h2> <p>To be more precise, I want to know what happens when a piece of javascript calls <code>navigator.geolocation.getCurrentPosition (success_func)</code> but <em>before</em> <code>success_func</code> actually gets called back. I want to know how the browser goes about obtaining the latitude and longitude coordinates. What's the protocol it uses? What servers does it query to obtain this information? etc.</p> <p>Here's what I have determined and tried:</p> <ul> <li>Chrome and Firefox uses the MAC of nearby wifi access points to obtain geolocation by sending it to googlesapi.com. It is this MAC-wifi based implementation I am most interested in.</li> <li>By the time <code>success_func</code> gets called, the browser has already obtained the geolocation data.</li> <li>I made limited progress using proxy and packet captures like tcpcatcher and wireshark. I see a query is being made to <code>googleapis.com:443</code> but of course it's over tls/ssl which means I can't read it. (using ssl monitor in tcpcatcher causes geoloc to fail in browser)</li> <li>I tried using builtin devtool and console in browser but it seems to omit the communication that grabs the geoloc data. For example, using chrome's devtool (<kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>I</kbd>), it does not show any <code>CONNECT</code> methods or connections to <code>googleapis.com</code> even though tcpcatcher clearly captures that during geolocation.</li> <li>I've tried looking at the source to determine this but not having much luck. The problem is that browser codebases are just humongous and locating the pertinent class and source files would be difficult especially since I'm unfamiliar with their overall design. grepping for interesting keywords only goes so far.</li> </ul> <p>If you guys were trying to determine and reverse the protocol a given browser uses to implement geolocation how would you guys proceed?</p> <h2>Other Resources</h2> <p>Here are some things I've already looked at that I found helpful:</p> <ul> <li><a href="http://samy.pl/mapxss/" rel="nofollow noreferrer">http://samy.pl/mapxss/</a></li> <li><a href="https://stackoverflow.com/questions/3041113/how-exactly-does-html5s-geolocation-work">https://stackoverflow.com/questions/3041113/how-exactly-does-html5s-geolocation-work</a></li> </ul> <p>The problem is some of the info mentioned there is out-of-date and no longer accurate. My aim now is to figure out exactly what changed and how an external custom application can use this protocol itself for geolocation.</p>
How to identify HTML5 geolocation protocol of a browser?
|tools|protocol|
<p>I think you have two questions here. The first part is how to convert from decimal to hexadecimal and back; the second part is how a multi-byte value is represented in memory. Guntram Blohm's answer covers the first part in detail, and I'll try to muddle through an answer to the second here.</p> <p>So, consider a multi-byte hexadecimal number...ABCD, where each letter represents a byte. So for example in 0x03B87C43 A represents 0x03, B represents 0xB8, C represents 7C and D represent 0x43. Finally, D is referred to as the low-order byte. </p> <p>Now, the various bytes can be arranged in different ways in memory; and there are two major forms that are currently in use today:</p> <p><strong>little-endian</strong> form:</p> <p>The low-order byte is placed at the lowest memory address, thus our example number would be stored in memory thusly:</p> <pre><code> 1000 1001 1002 1003 &lt;----- memory addresses, notional +-----+-----+-----+-----+ | D | C | B | A | +-----+-----+-----+-----+ </code></pre> <p>Intel processors use this form of storing multi-byte numbers.</p> <p><strong>big-endian</strong> form:</p> <p>The low-order byte is placed at the highest memory address, thus our example number would be stored in memory thusly:</p> <pre><code> 1000 1001 1002 1003 &lt;----- memory addresses, notional +-----+-----+-----+-----+ | A | B | C | D | +-----+-----+-----+-----+ </code></pre> <p>Non-Intel SUN workstations use this form (IIRC they use a Motorola processor).</p> <p>other forms.</p> <p>just about any other arrangement can be used. For example, PDP-11 used a system where a 32-bit value was stored in little-endian format, with the exception of each byte of the 16-bit half was swapped. Thus our sample number would be stored in memory as:</p> <pre><code> 1000 1001 1002 1003 &lt;----- memory addresses, notional +-----+-----+-----+-----+ | C | D | A | B | +-----+-----+-----+-----+ </code></pre> <p>Hope this helps a bit.</p>
5995
2014-08-01T03:58:03.317
<p>I am learning some gdb and it is covering examining arrays. There is the following code, and I see it is 4 bytes, and how <code>a[1] = 2</code> in an array <code>int a[] = {1,2,3}</code></p> <pre><code>(gdb) x/4xb a + 1 0x7fff5fbff570: 0x02 0x00 0x00 0x00 </code></pre> <p>But what if a was greater than what could be shown by a single hex byte? Then how does it work for the second part? Sorry if this is unclear, I don't know how tow ord it exactly.</p>
Hex representation of integer values in excess of FF (255)
|gdb|
<p>Floating point support is possible. I think there are two reasons why it's not common:</p> <ul> <li><p>Most applications of binary ILs don't work with floating point. For example, most SMT solvers only have support for integer arithmetic operations. Modeling behavior is not very useful if one cannot reason about it.</p></li> <li><p>There are not many mature libraries for arbitrary precision floating point code that can be readily pulled into these projects.</p></li> </ul>
5998
2014-08-01T16:05:48.347
<p>Are there any technical hurdles to implementing floating point support in re-oriented intermediate languages? I ask because none seem to support it, but give few reasons why. The only comment on the topic I've seen is from Sebastian Porst who in 2010 merely said</p> <blockquote> <p>REIL is primarily made to find security-relevant bugs in code. FPU code pretty much never plays a role in such code.</p> </blockquote>
Floating point in RE intermediate languages like vine il, bap il, and google/zynamics reil
|static-analysis|
<p>Not a GUI tool, but <a href="http://practicalmalwareanalysis.com/fakenet/" rel="noreferrer">FakeNet</a> is a good alternative.</p> <blockquote> <p>FakeNet is a tool that aids in the dynamic analysis of malicious software. The tool simulates a network so that malware interacting with a remote host continues to run allowing the analyst to observe the malware’s network activity from within a safe environment. The goal of the project is to:</p> <pre><code>- Be easy to install and use; the tool runs on Windows and requires no 3rd party libraries - Support the most common protocols used by malware - Perform all activity on the local machine to avoid the need for a second virtual machine - Provide python extensions for adding new or custom protocols - Keep the malware running so that you can observe as much of its functionality as possible - Have a flexible configuration, but no required configuration </code></pre> </blockquote> <p><a href="https://www.mandiant.com/resources/download/research-tool-mandiant-apatedns" rel="noreferrer">Mandiant's ApateDNS</a> is a good tool for responding with fake DNS response:</p> <blockquote> <p>Mandiant ApateDNS is a tool for controlling DNS responses though an easy to use GUI. As a phony DNS server, Mandiant ApateDNS spoofs DNS responses to a user-specified IP address by listening on UDP port 53 on the local machine. Mandiant ApateDNS also automatically sets the local DNS to localhost. Upon exiting the tool, it sets back the original local DNS settings.</p> </blockquote> <p><img src="https://i.stack.imgur.com/c0ETV.png" alt="enter image description here"></p>
5999
2014-08-01T17:30:52.570
<p>I found a tool for Linux called <a href="http://www.inetsim.org/about.html" rel="nofollow">INetSim</a> which emulates services such as HTTP HTTPS IRC and many other. It is often used to trick malware. The problem is that INetSim works only on Linux. So I want Windows based tool for Win 7 32bit which is alternative to this ( I prefer a gui one ) </p>
Are there any Windows alternatives to INetSim?
|tools|dynamic-analysis|
<p>A <em>magic number</em> is a set of bytes used when accessing a file to determine its type. For example, the standard Microsoft PE begins with (in ASCII) <code>MZ</code>, the initials of one of the developers of MS-DOS.</p> <p>The initial headers in a portable executable specify a variety of information regarding the file, ranging from the supported platform, number of symbols, number of sections, time stamps, etc. As such, it is a logical location to store the magic number, as it is also part of the file metadata.</p> <blockquote> <p>How can a malware analyst benefit from this magic number?</p> </blockquote> <p>The only information the magic number provides is the file type, and as such that is all that can be garnered by a malware analyst, or any type of analysis. Although one can refer to the file extension to check a file type, they can be changed without affecting the contents of the file. As such, checking the magic number is a method to determine the true file type. Discrepancies would then indicate potential malicious behavior or attempts to hide data.</p>
6012
2014-08-03T08:45:57.663
<p>While checking the PE header of DLLs and EXE(s) by PEviewer, I found something called "<em>magic number</em>". </p> <p>After googling "<em>magic number</em>". I found that it is used to determine the file type. My question is how can a malware analysist benefits from this magic number ? And why is it in the PE header ?</p>
Is the magic number important
|static-analysis|pe|
<p>To answer the original question, what you can do is to hook <a href="http://doxygen.reactos.org/d8/d55/ldrutils_8c_a8fabcfb642b2788989401d1ac7cee130.html" rel="nofollow"><code>LdrpCallInitRoutine</code></a> in <code>ntdll.dll</code>. This function is used by DLL loading/unloading code to actually call the DLL entry point (<code>DllMain</code>) and also the TLS callbacks. The first argument is the address to be called:</p> <pre><code>BOOLEAN NTAPI LdrpCallInitRoutine(PDLL_INIT_ROUTINE EntryPoint, PVOID BaseAddress, ULONG Reason, PVOID Context); </code></pre>
6018
2014-08-03T20:17:39.410
<p>I have written a C API with support for static import hooking via overwriting the corresponding IAT entry of an exported function. It works nicely for older simple applications, but for more modern applications, it is less effective. This is primarily due to the large amount of applications nowadays that dynamically import functions. </p> <p>My solution to this problem was to create the process in an initial suspended state and then hook the <code>LoadLibrary(Ex)(A/W)</code> family of functions along with <code>GetProcAddress()</code> to replace the retrieved address of a target function with my own. That solution is limited in part due to the fact that it is based off the application only importing dynamic functions and libraries in the executable module, without working for processes created later ( although that could be solved by hooking <code>CreateProcess()</code> ) or more importantly, <strong>it doesn't handle the DLLs in the application that also call the target functions I want to hook</strong>. This is obviously because the DLLs have a separate import section in their own PE from the executable module. </p> <p>Which brings me to my question, <em>how do I hook the entry point of a DLL</em>? I want to implement that method because I need the DLL to be bound to the libraries it imports statically, so I can hook the LoadLibrary/GetProcAddress functions in before the DLL has a chance to load/import them in DLLMain. I'm assuming there is a way to do this by changing the entry point of the DLL, or by hooking a lower level function that handles calling a DLL entry point in kernel32.dll. </p> <p>If the method I'm requesting has a better alternative, then I would gladly accept that solution as well if it achieves my desired effect.</p> <p>My processor is an AMD Athlon II X2 250 that is x86-x64 compatible, and my operating system is Windows 7.</p>
How to hook the entry point of a DLL?
|windows|c|dll|pe|function-hooking|
<p>The syntax is incorrect, but the code is basically what IsDebuggerPresent does.</p> <ol> <li>Get a pointer to the <a href="http://en.wikipedia.org/wiki/Thread_Environment_Block" rel="nofollow">TEB</a> (located at fs:18h)</li> <li>Get a pointer to the <a href="http://en.wikipedia.org/wiki/Process_Environment_Block" rel="nofollow">PEB</a> (located at teb+30h)</li> <li>Check the BeingDebugged flag (located at peb+2)</li> </ol> <p>The syntax should be something like:</p> <pre><code>mov eax, large fs:18h mov eax, [eax+30h] movzx eax, byte ptr [eax+2] </code></pre> <p>If you don't understand assembler syntax, though, you're generally going to have a bad time when analyzing malware.</p>
6024
2014-08-05T18:18:22.163
<p>While reading a book it mentioned that the following code is usually used to as an antidebugger </p> <pre><code>mov eax, large fs:18h mov eax, [eax+30h] movzx eax, byte ptr [eax+2] retn </code></pre> <p>I don't understand what are the keywords <code>large</code> , <code>byte</code>, <code>ptr</code> and <code>retn</code>. I am new learner of assembly and its usage in malware.</p>
How does this test for debugger
|assembly|malware|anti-debugging|
<p>An instruction is bytes that can be decoded. They may or may not be real instruction by virtue of not being called. Might be data that looks like possible code. </p> <p>Functions is instructions that have been indicated are called and this is the start. The indication might be a user action like pressing <kbd>P</kbd> or <kbd>auto analysis</kbd> following call locations in other code/functions. </p> <p>But, in either case you can tell IDA that something is or is not code or functions. The only trick is if some bytes of a function are not valid instructions, then IDA will not lets you create a function. </p>
6026
2014-08-06T08:22:41.997
<p>I am newbie in IDA Pro. I have a basic question, what is the difference between instruction and function in IDA Pro? Is function contains some instructions on it ?!</p> <p>Thanks in advance :)</p>
Difference between Instruction and Function in IDA Pro
|ida|
<p>Depending how extensive your modifications are, the way I've always done it was to only compile the snippet you want to inject (or manually convert the OpCodes) and patch the existing binary rather than recompile</p> <p>also, IlSpy may be easier for what you want as you can simply go:</p> <p>.net binary > c# decompiled > .net binary</p> <p><a href="http://ilspy.net" rel="nofollow">http://ilspy.net</a></p>
6029
2014-08-06T15:59:41.050
<p>I disassembled a C# program with ildasm and modified the il code to my needs but now when i try to assemble it back into an exe i get these errors:</p> <pre><code>Cannot compile native/unmanaged method Local (embedded native) PInvoke method, the resulting PE file is unusable </code></pre> <p>I have generated a snk file and tried to use that with ilasm but i still get the same errors.</p> <p>EDIT: These errors were given by ilasm when i try to reassemble the .il file. I also tried to edit the code in Reflector but after editing and trying to save it says that it cannot save mixed mode assemblies. Maybe i would be able to edit the binary in HEX editor?</p>
Cannot compile native/unmanaged method
|c#|
<p>If you build with <code>--enable-debug[=heavy]</code> and run the program via debug.com, it automatically breaks on the first instruction. See the <code>DOS_Execute</code> function in <a href="https://github.com/Henne/dosbox-svn/blob/master/src/dos/dos_execute.cpp#L479" rel="noreferrer">src/dos/dos_execute.cpp</a> and <code>DEBUG_CheckExecuteBreakpoint</code> in <a href="https://github.com/Henne/dosbox-svn/blob/master/src/debug/debug.cpp#L2080" rel="noreferrer">src/debug/debug.cpp</a>.</p>
6037
2014-08-07T15:22:05.090
<p>DOSbox compiled with <code>--enable-debug=heavy</code> option becomes a powerful reversing tool. Anytime I feel like checking the disassembly and memory state I just hit <kbd>Alt</kbd>+<kbd>Pause</kbd>.</p> <p>But, what if I want to see the very first instructions of the program ? How do I start the application so that it immediately enters debug mode before even starting execution ?</p>
How to start a DOS application in DOSbox in debug mode?
|disassembly|debugging|dos|
<p>Here's a fun, quick little trick if in a Windows environment and you're checking for an x86 or x64 binary:</p> <ol> <li>Right-click on the application.</li> <li>Click <code>Properties</code>.</li> <li>Click the <code>Compatibility</code> tab.</li> <li>In the <code>Compatibility mode</code> section, check the <code>Run this program in compatibility mode for:</code> box.</li> <li>If you see <code>Windows 95</code> as an option from the drop-down, then it's a 32-bit application. If you do not, then it's a 64-bit application.</li> </ol>
6040
2014-08-08T08:42:06.503
<p>How to check if Windows executable is 64-bit reading only its binary. Without executing it and not using any tools like the SDK tool <a href="http://msdn.microsoft.com/en-us/library/c1h23y6c.aspx"><code>dumpbin.exe</code></a> with the <code>/headers</code> option.</p>
Check if exe is 64-bit
|windows|pe|executable|
<p>The PSP is a process table, it holds information about a running process (application), it is created and filled by the loader. The loader uses the EXEHDR information to fill some of the fields of the PSP and else. After creating the PSP the loader grabs the application code (whatever comes after the EXEHDR up to the end of the file and loads just after the PSP.</p> <p>The PSP occupies the beginning of an application (COM and EXE) allocated memory; the PSP offset in the segment is always 0000H - 100H. When your application starts, DS and ES segments points to PSP, you have to adjust them to your application data segment before proceeding.</p> <p>Segments are not fixed, they are defined based on the free memory space, but offsets within a segment are always the same, otherwise your applicaton would break, all your data and code is defined (calculated) base on offsets from the beginning of a segment.</p> <p>CS is filled by the loader after allocating memory and loading your program, IP is also filled by the loader, this information is extracted from the EXEHDR (the offset of the application entry point (it is calculated by the assembler/compiler when it builds the object code), but its defined by the programmer in assembly, it is the label set after the directive END in masm, or by the compiler, in c is the main function offset ).</p>
6048
2014-08-10T12:16:12.517
<p>I'm using IDA to disassemble <a href="http://www.myabandonware.com/game/test-drive-iii-the-passion-119" rel="nofollow">Test Drive III</a>. It's a 1990 DOS game. The *.EXE has MZ format.</p> <p>The game uses a number of anti-reversing features such as copying its code to segment <code>(PSPseg+2be7)</code> where <code>PSPseg</code> is the initial value of <code>ES</code> (i.e. the segment where PSP resides). As far as I know, <a href="http://en.wikipedia.org/wiki/COM_file" rel="nofollow">COM executables</a> are always loaded right after the end of <a href="http://en.wikipedia.org/wiki/Program_Segment_Prefix" rel="nofollow"><code>Program Segment Prefix (PSP)</code></a>, so that both PSP and exe fit into one segment. What about MZ executables? Is there any fixed place where application's PSP is located relatively to the application itself?</p> <p>In other words, is the <code>base-PSPseg</code> offset always the same? On my <a href="http://www.dosbox.com/" rel="nofollow">DOSBox</a> at the start of the program execution <code>CS</code> is always <code>0x22CF</code>, <code>ES=DS=0x01FE</code>, <code>CS0</code> in the MZ header is <code>0x20C1</code>, yielding <code>base-PSPseg</code> offset <code>0x0010</code> (16 segments, 256 bytes - exactly the size of PSP).</p> <p>If this offset is not fixed and both PSP and the application are just loaded randomly in whatever memory location is big enough, then is there at least any guarantees about their addresses? Like that PSP address is always lower than the app's base address?</p>
Any correlation between DOS Program Segment Prefix and the base address of loaded executable?
|disassembly|x86|dos|dos-exe|segmentation|
<p>The <code>!</code> denotes <em>writeback of the base register</em>. <strong>Base register</strong> is the register used to address the memory to be read or written - in your case it's <code>R4</code>. <strong>Writeback</strong> means that the base register will be updated with the delta equal to the size of transferred data.</p> <p>So, the instruction </p> <pre><code>ldm r4!, {r0, r1, r2, r3} </code></pre> <p>can be represented by the following pseudocode:</p> <pre><code>r0 = *(int)(r4) r1 = *(int)(r4+4) r2 = *(int)(r4+8) r3 = *(int)(r4+12) r4 = r4 + 16 // writeback (16 bytes transferred) </code></pre> <p>In the variant without <code>!</code> the writeback doesn't happen so <code>R4</code> retains the original value.</p> <p>In the <code>LDR</code> and <code>STR</code> instructions you may also encounter <em>pre-indexed</em> and <em>post-indexed</em> notation:</p> <pre><code>LDR R0, [R4, #4] ; simple offset: R0 = *(int*)(R4+4); R4 unchanged LDR R0, [R4, #4]! ; pre-indexed: R0 = *(int*)(R4+4); R4 = R4+4 LDR R0, [R4], #4 ; post-indexed: R0 = *(int*)(R4+0); R4 = R4+4 </code></pre> <p>For more information see the <a href="http://www.keil.com/support/man/docs/armasm/">ARM Assembler Guide</a>.</p>
6061
2014-08-12T16:38:24.023
<p>I am quite new to ARM assembly, I already saw that the bang (<code>!</code>) is used to really update a register after a computation in the addressing mode syntax, but I can't figure out what is the difference of semantics between (this output is from <code>objdump</code> so it uses <code>gas</code> syntax):</p> <pre><code>ldm r4!, {r0, r1, r2, r3} </code></pre> <p>And:</p> <pre><code>ldm r4, {r0, r1, r2, r3} </code></pre> <p>Any idea ?</p>
What is the meaning of '!' in ldm arm assembler instruction?
|assembly|arm|gas|
<ol> <li><p>Yes, <code>C</code> is the carry flag.</p></li> <li><p><code>C</code> is set from the result of the <code>ROR</code> operation. </p></li> </ol> <p>Pseudocode of the <code>AND (register)</code> instruction from the <a href="http://infocenter.arm.com/help/topic/com.arm.doc.ddi0406c/index.html" rel="nofollow">ARM ARM</a>:</p> <pre><code>if ConditionPassed() then EncodingSpecificOperations(); (shifted, carry) = Shift_C(R[m], shift_t, shift_n, APSR.C); result = R[n] AND shifted; if d == 15 then // Can only occur for ARM encoding ALUWritePC(result); // setflags is always FALSE here else R[d] = result; if setflags then APSR.N = result&lt;31&gt;; APSR.Z = IsZeroBit(result); APSR.C = carry; // APSR.V unchanged </code></pre> <p>As you can see, <code>APSR.C</code> is set to the result of the shift operation, not the <code>AND</code> operation.</p> <p>Now, <code>AND</code> is pretty straightforward but in case of e.g. <code>ADD</code> you may have carry affected by both the shift and the add. So what happens? Again, ARM ARM to the rescue:</p> <pre><code>if ConditionPassed() then EncodingSpecificOperations(); shift_n = UInt(R[s]&lt;7:0&gt;); shifted = Shift(R[m], shift_t, shift_n, APSR.C); (result, carry, overflow) = AddWithCarry(R[n], shifted, APSR.C); R[d] = result; if setflags then APSR.N = result&lt;31&gt;; APSR.Z = IsZeroBit(result); APSR.C = carry; APSR.V = overflow; </code></pre> <p>The answer: the add "wins" and the carry of the shift operation is discarded.</p> <p>BTW, a good page to check what happens for each concrete instruction is <a href="http://svr-acjf3-armie.cl.cam.ac.uk/main.cgi" rel="nofollow">here</a>. For example:</p> <pre><code>ands r9, r0, r0, ror #3 machine code: E01091E0 ... cpsr.N ← (r0 AND r0 ROR 3)&lt;31&gt; cpsr.Z ← r0 AND r0 ROR 3 = 0 cpsr.C ← #CARRY (ROR_C (r0,3)) r9 ← r0 AND r0 ROR 3 r15 ← r15 + 4 adds r9, r0, r0, ror #3 machine code: E09091E0 ... cpsr.N ← (r0 + r0 ROR 3)&lt;31&gt; cpsr.Z ← r0 + r0 ROR 3 = 0 cpsr.C ← #CARRY (AddWithCarry (r0,r0 ROR 3,False)) cpsr.V ← #OVERFLOW (AddWithCarry (r0,r0 ROR 3,False)) r9 ← r0 + r0 ROR 3 r15 ← r15 + 4 </code></pre>
6065
2014-08-13T13:30:34.913
<p>Still looking at ARM assembler semantics (and, I try hard to read the specification, I ensure you!!!). I have some doubts about the ARM bit-shift instructions in general and <code>RRX</code> in particular.</p> <p>Lets start with <code>RRX</code>. </p> <p>From <a href="http://www.davespace.co.uk/arm/introduction-to-arm/barrel-shifter.html" rel="nofollow noreferrer">Davespace, Introduction to ARM, section <em>Barrel Shifter</em></a>, we see that <code>RRX</code> correspond to:</p> <p><img src="https://i.stack.imgur.com/Fcyhv.png" alt="RRX: Barrel RollRotate Right Extended"></p> <p>I suppose the <code>C</code> to be the carry flag found in the CPSR, is it correct ?</p> <p>Second question, in the case of the following instruction:</p> <pre><code>ands r9, r0, r0, ror #3 </code></pre> <p>I read that the carry flag (<code>C</code>) is set to the value of the last bit shifted out by the shifter operand (here <code>ROR</code>). </p> <p>My problem is that the <code>ands</code> is also supposed to update the CPSR because of its flag <code>s</code>. So, who is winning at the end ? And, what is left in the final carry flag ? The value resulting of <code>AND</code> or the value resulting of <code>ROR</code> ?</p>
Semantics of the RRX shift instruction in ARM and Carry flag updates?
|assembly|arm|
<p>I dealt with a ROM image once and faced this problem. I was confused too about what to do until Igor offered his advice.</p> <p>What seemed to be happening was that the linker was placing every object file into its own segment, so every inter-object function invocation was rendered in the binary as a far call, where the segment base was the base given to all functions within the module. I.e., the case you mention in your reply to Igor's comment did not materialize for me.</p> <p>To fix it, I searched the binary for all far call instructions and then created a new IDA segment (as large as possible) at the linear address of each referenced x86 segment. I.e., I did indeed end up with lots of tiny segments. This is not really a problem; really, the problem is that by not doing this, the references won't be disassembled correctly. It was pretty quick work and probably could be automated with a script.</p>
6067
2014-08-13T14:20:53.240
<p>I'm disassembling a packed 16 bit DOS MZ EXE.</p> <p>To deobfuscate it, I've set a breakpoint in DOSbox at the end of the unpacking routine, let it run, and made a memory dump. This way I essentially got the deobfuscated EXE image.</p> <p>Problems started when I loaded the image in IDA. You see, I don't understand the IDA's concept of segments. They are similar to x86 segments, but there are numerous differences which I can't grasp. When IDA asked me to create at least one segment, I just made a single huge segment 1 MB length, because the code and data in program's address space are mixed and it doesn't make sense to introduce separate segments such as <code>CODE</code>, <code>DATA</code> etc. </p> <p>After showing IDA the entry point, everything worked fine: IDA successfully determined functions, local variables, arguments etc. The only problem is that some calls are marked as <code>NONAME</code>, even though they point at correct subroutines. The strangest thing is that those subroutines have correct XREFs to the 'illegal' calls. Here's an example:</p> <pre><code>seg000:188FF 004 call 1AD9h:1 ; Call Procedure </code></pre> <p>This line is red and has an associated <code>NONAME</code> problem in Problems List. Why?</p> <p>The <code>1AD9h:1</code> seg:offset address corresponds to linear address <code>0x1ad91</code>, which has this:</p> <pre><code>seg000:1AD91 ; =============== S U B R O U T I N E ======================================= seg000:1AD91 seg000:1AD91 ; Attributes: bp-based frame seg000:1AD91 seg000:1AD91 sub_1AD91 proc far ; CODE XREF: sub_188F2+DP </code></pre> <p>Note the XREF. So IDA actually processes the call correctly! Why is the call considered invalid? IDA help file says this:</p> <blockquote> <h2>Problem: Can not find name</h2> <p><strong>Description</strong></p> <p>Two reasons can cause this problem:</p> <ol> <li>Reference to an illegal address is made in the program being disassembled;</li> <li>IDA couldn't find a name for the address but it must exist. </li> </ol> <p><strong>What to do</strong></p> <ol> <li><p>If this problem is caused by a reference to an illegal address</p> <ul> <li>Try to enter the operand manually</li> <li>Or <strong>make the illegal address legal by creating a new segment</strong>.</li> </ul></li> <li><p>Otherwise, the database is corrupt.</p></li> </ol> </blockquote> <p>So, I guess the problem is that I have one gargantuan segment instead of several small ones. But, how do I properly divide the address space into appropriate segments? </p> <p>I know the register values (including <code>DS</code>, <code>CS</code>, <code>SS</code>, <code>IP</code>, etc) at the entry point. Let's assume I create a <code>CODE</code> segment starting from the segment corresponding to the CS register value at the entry point. But what length should this segment have ?</p> <p>What's the point of segments in IDA at all? If DATA segments can contain instructions, and CODE segments can be read and written as data?</p> <p>Please excuse me for such a newbie question, but official IDA manual is notoriously scarce and HexRays forums are closed for me because I use freeware version. </p>
Segments in IDA. How to overcome NONAME problem
|ida|disassembly|segmentation|
<p>DOS programs used segments and IDA was made to mimic that behavior. That's why you cannot change CS (since in properly set up database CS is just the segment's base) and why your changes to segment registers do now show up (because there is no segment corresponding to the values you enter).</p> <p>I would suggest opening a normal (not packed) MZ file to see how it's supposed to look. If you keep fighting IDA instead of working with it you'll keep having problems.</p>
6069
2014-08-13T18:18:38.470
<p>I'm disassembling a packed 16 bit DOS MZ EXE.</p> <p>To deobfuscate it, I've set a breakpoint in DOSbox at the end of the unpacking routine, let it run, and made a memory dump. This way I essentially got the deobfuscated EXE image. Then I loaded this image in IDA.</p> <p>Obviously, there's no MZ header anymore, so IDA can't know the application's entry point and initial values of CS, SS and other segment registers. I, however, do know these values, and I'm willing to supply them to IDA. To do this, I hit <kbd>Alt</kbd>+<kbd>G</kbd> and type the register's value.</p> <p>However, instead of showing <code>assume ds:&lt;value&gt;</code>, IDA shows</p> <pre><code>seg000:1AEBC assume es:nothing, ss:nothing, ds:nothing </code></pre> <p>Why?</p> <p>Another question. Why there is no option to set the value of CS register? Consider code which contains near jumps. Without knowledge about the CS register value, IDA won't be able to proceed with disassembling. But I <em>do</em> know what value CS has at this specific point! How do I supply this information to IDA if the <code>Segment Register Value</code> dialog window doesn't have CS option?</p>
Why IDA aggressively assumes 'nothing' on segment registers?
|ida|disassembly|segmentation|
<p>Structurally, it resembles HC-256, but it's hard to say for certain without running it and comparing the input/output to an existing HC-256 implementation. </p>
6073
2014-08-14T02:13:14.243
<p>I have a decryption algorithm that has been pulled from an x86 binary and converted into C# code. The C# works perfectly to decrypt data, but I'd like to identify the algorithm in use, so I could (among other things) possibly replace the extracted algorithm with an identical one from a third party library (like <a href="https://www.bouncycastle.org/" rel="nofollow">Bouncy Castle</a>) but I don't know where to begin.</p> <p>I'm including my code below for reference. I'd like to find out how to even go about identifying such a thing. (Of course, the name of the algorithm would be greatly appreciated as well!)</p> <pre><code>public class Crypto { private static uint[] _MCInitVector = { 0xDB792195, 0xE63BF923, 0x4F6F076D, 0x122CDED5, 0xDA711220, 0x4F6FCEE6, 0x45E45C44, 0xCF852932, 0x469ADBF6, 0x5E12481F, 0x682D2354, 0xBDD21105, 0x5BB5F3E6, 0x6E8C82CA, 0xD0FDD8E3, 0xBE4CB2DF, 0xE3EB3F01, 0xD03D3F32, 0x77A4E3FF, 0xDF17D4B5, 0x2AC710AC, 0x5ACAC8ED, 0x703BD8E4, 0x1D9C3B3B, 0x4564A5D2, 0xB0224742, 0xB5A3048A, 0xA35A3F55, 0xCA33744F, 0xF1AEC0A0, 0x0BF4B1A4, 0x04038654, 0x7C65A9EC, 0xAA41DC51, 0xE5096687, 0x1D433C75, 0x35DE20AF, 0xDB75DA77, 0x230A8E81, 0x18BE6B31, 0x8D8857BA, 0x0EC016A2, 0x2FF6FB27, 0x37D3EB09, 0x91A6A259, 0x13E0EA7B, 0x07926A43, 0x21DF97F9, 0x24FD4BEB, 0x10315AA3, 0x58D70DF3, 0x7C56F52D, 0x1ABF4E8F, 0x50E140B0, 0xE1E9FEB2, 0x90380A5E, 0xEA3761D3, 0x583B843B, 0xF0F9496F, 0xC9FCD225, 0x35EC4846, 0x550CFA8B, 0x574DD012, 0x66C3ABF9, 0x55A7DBF8, 0x510A4DAE, 0xFF1738CC, 0x9AC85D2F, 0x3A7704F5, 0xDDB85A5C, 0x86A50929, 0xFB01BD4F, 0x877DDF76, 0x187EF004, 0x912E5B3E, 0xEBE1CBDD, 0x354F0206, 0x9D889D03, 0x910D16EF, 0xA67178A7, 0xC2DEEEDF, 0xE433A4BC, 0x474B91F7, 0x14A28299, 0xCBAD7D66, 0x494D39DF, 0x8B6BB28E, 0xCDCC33EE, 0xAF37C9D3, 0x9D79794F, 0x6B2C05ED, 0xA8823F18, 0x6225D7ED, 0x292E7345, 0xA04CE9DF, 0x951ABE7F, 0x72C3CC98, 0xCD1E0582, 0x41224C23, 0x90D26E39, 0xC75B1461, 0xE0B5DBD1, 0x83BA4F78, 0x2A072F2B, 0xA1A24F28, 0xB3BF06C8, 0xD5335518, 0x186662AC, 0xBC71C21F, 0x2BFC24A8, 0xDBB15F07, 0x076C83F5, 0xBD656129, 0x507A23D6, 0xB3CE5930, 0xD68E24EF, 0xE82CAF40, 0xA53C0493, 0x79CE3BB7, 0x030FEF29, 0x347E8A30, 0xFF6E9D5C, 0xCE9B9A04, 0xBC4E5140, 0x949BBE83, 0xCB8B3DBE, 0xAE1D5F44, 0x21148102, 0x754E9EAF, 0xF2DEAE15, 0xF2EB3A8C, 0x8B1614AE, 0x6ED005B6, 0xCA16DD83, 0x29BD701B, 0xAA6201C9, 0x58CE4025, 0x9C6121CB, 0x11C03985, 0xEFFC2A2A, 0x4136605B, 0x7F30DDFD, 0x19ECCC35, 0x4D6E1426, 0x6360EE03, 0xE69CB55A, 0xD181A69D, 0x7E69A4C7, 0x91B4C97C, 0x9BA0F967, 0xE05438A6, 0xF6A6AB45, 0xD0808096, 0xCE1DB289, 0x8FDF796F, 0x4D3B9B25, 0xA4AD9AE6, 0x5DF9105F, 0x71B1FD3E, 0xF90A6F7C, 0xEE1D1310, 0x183B6922, 0x2AD9A280, 0x50EAD939, 0x0B5990F6, 0xEAB6D31C, 0xD1F23104, 0x3FA68196, 0xA228DCCC, 0x68C10912, 0x9003CF9C, 0xB92E58C4, 0x9FBBA10F, 0x3DA05555, 0xAE52996D, 0x8F0A3B2C, 0x12F8D4DF, 0x02DF25C9, 0x51D99D11, 0x950AEAD2, 0xFFF87B29, 0xCDA6B1E7, 0x13056DC7, 0x189BA81A, 0xA23C22E1, 0x0F9E5E7F, 0x799B23CD, 0x53DB90F6, 0xA388548B, 0xB9C0D3E5, 0x753BB810, 0xC3768EFD, 0x2D66B7F2, 0x16EEC5CB, 0x4490D722, 0xF813E0E6, 0xD02DC104, 0x1FE5CA4F, 0x18A27E69, 0x191699FF, 0xB366A330, 0x4B01495D, 0x5529AD4D, 0x48F2FE87, 0x926C55F1, 0x53491F9B, 0x875BA8D1, 0xEF2C3CD8, 0xE50C89F9, 0x5201768C, 0x1A5C4B35, 0x114C0C76, 0x77D8B1DF, 0x75E77E8A, 0x39826BA2, 0x3FFACC4F, 0xF5FF4FF7, 0xA0B10525, 0xFD46ED4F, 0xE97C9F45, 0x568CB141, 0xD45C1365, 0x788B2B7E, 0xABAA5158, 0x73AD6AEA, 0x041E5FCA, 0x0BE48855, 0x01C285AF, 0x0B2EFB29, 0x49655AEE, 0xABBF0B3C, 0x958E4617, 0x0A8CD37A, 0x871758F9, 0x0DB1A84D, 0xE453974A, 0x78308BD6, 0x7456A7EB, 0x76FF0F79, 0x3C1957D9, 0xD6E89EE6, 0x4DB3A5B2, 0xBAC849BA, 0xC68E2110, 0xE8F9F2EB, 0x970F676E, 0x034377B6, 0xF0DC724F, 0xFF290056, 0xD3B7F2FF, 0x72DF023B, 0x3021ACA2, 0x352EE316, 0xE046B5CA, 0xE94E08BC, 0x41BFFB5A }; private byte[] _decryptKey; private uint[] _decryptSet; private uint _decryptState1; private uint _decryptState2; private uint _decryptState3; private int _decryptSetIndex; private int _decryptKeyIndex; public uint Seed { get; set; } public Crypto(uint seed) { this.Seed = seed; _decryptKey = new byte[128]; _decryptSet = new uint[512]; // round 0 Array.Copy(_MCInitVector, _decryptSet, 256); Array.Clear(_decryptSet, 256, 256); _decryptState1 = seed; _decryptState2 = 0; _decryptState3 = 0; _decryptSetIndex = 0; uint key = getNextKey(); // round 1 Array.Copy(_MCInitVector, _decryptSet, 256); Array.Clear(_decryptSet, 256, 256); _decryptState1 = seed; _decryptState2 = key; _decryptState3 = 0; _decryptSetIndex = 0; for (int i = 0; i &lt; 5; i++) { key = getNextKey(); } // round 2 Array.Copy(_MCInitVector, _decryptSet, 256); Array.Clear(_decryptSet, 256, 256); _decryptState1 = key; _decryptState2 = 0; _decryptState3 = 0; _decryptSetIndex = 0; // fill decrypt keys _decryptKeyIndex = 31; for (int i = 124; i &gt;= 0; i -= 4) { BitConverter.GetBytes(getNextKey()).CopyTo(_decryptKey, i); } } private uint getNextKey() { int i = (--_decryptSetIndex); if (i &lt; 256) { uint var1 = _decryptState1; uint var2 = _decryptState2 + (++_decryptState3); i = 0; while (i &lt; 256) { uint j, k; var1 = (var1 ^ (var1 &lt;&lt; 13)) + _decryptSet[(i + 128) &amp; 0xff]; j = _decryptSet[i]; k = _decryptSet[i] = _decryptSet[(j &amp; 0x3ff) &gt;&gt; 2] + var1 + var2; var2 = _decryptSet[i + 256] = _decryptSet[((k &gt;&gt; 8) &amp; 0x3ff) &gt;&gt; 2] + j; i++; var1 = (var1 ^ (var1 &gt;&gt; 6)) + _decryptSet[(i + 128) &amp; 0xff]; j = _decryptSet[i]; k = _decryptSet[i] = _decryptSet[(j &amp; 0x3ff) &gt;&gt; 2] + var1 + var2; var2 = _decryptSet[i + 256] = _decryptSet[((k &gt;&gt; 8) &amp; 0x3ff) &gt;&gt; 2] + j; i++; var1 = (var1 ^ (var1 &lt;&lt; 2)) + _decryptSet[(i + 128) &amp; 0xff]; j = _decryptSet[i]; k = _decryptSet[i] = _decryptSet[(j &amp; 0x3ff) &gt;&gt; 2] + var1 + var2; var2 = _decryptSet[i + 256] = _decryptSet[((k &gt;&gt; 8) &amp; 0x3ff) &gt;&gt; 2] + j; i++; var1 = (var1 ^ (var1 &gt;&gt; 16)) + _decryptSet[(i + 128) &amp; 0xff]; j = _decryptSet[i]; k = _decryptSet[i] = _decryptSet[(j &amp; 0x3ff) &gt;&gt; 2] + var1 + var2; var2 = _decryptSet[i + 256] = _decryptSet[((k &gt;&gt; 8) &amp; 0x3ff) &gt;&gt; 2] + j; i++; } _decryptState1 = var1; _decryptState2 = var2; i = _decryptSetIndex = 511; } return _decryptSet[i]; } public void DecodePacket(ref byte[] packet) { int len = packet.Length; // Poster's note: Packet is post-fixed with a 4 byte checksum, hence this subtraction len -= 4; int idx = _decryptKeyIndex * 4; int i = 6; // Poster's Note: Actual packet data starts at index 6, index 5 and below are flags/metadata // block decryption (OFB mode) while (i &lt; len) { int j = idx &amp; 0x1f; idx += 4; packet[i++] ^= _decryptKey[j++]; packet[i++] ^= _decryptKey[j++]; packet[i++] ^= _decryptKey[j++]; packet[i++] ^= _decryptKey[j++]; } len += 4; // process left bytes while (i &lt; len) { packet[i++] ^= _decryptKey[(idx++) &amp; 0x7f]; } // update key stream idx = _decryptKeyIndex; BitConverter.GetBytes(getNextKey()).CopyTo(_decryptKey, idx); _decryptKeyIndex = (idx + 31) &amp; 0x1f; } } </code></pre>
Identifying cryptography algorithm
|static-analysis|decryption|cryptography|c#|
<p>I have extensive experience with parsing the PE on Windows, mainly for use in function interception. Here are the steps you should follow to achieve your goal.</p> <p>The first step is to find the base address of the image loaded into memory. This step will be different depending on if the executable has or hasn't been mapped into memory, but the basic idea will be the same. Assuming that you are interested in doing this for a file on disk, then you may do this with the <a href="https://docs.microsoft.com/en-us/windows/win32/memory/file-mapping" rel="nofollow noreferrer">file mapping API</a>, if you would prefer to implement this on an executable loaded into memory as a running process, you can achieve the equivalent by using the the <a href="https://docs.microsoft.com/en-us/windows/win32/toolhelp/traversing-the-module-list" rel="nofollow noreferrer">tool help snapshot API</a>. The base address will be the same as the field <code>hModule</code> in the <a href="https://docs.microsoft.com/en-us/windows/win32/api/tlhelp32/ns-tlhelp32-moduleentry32" rel="nofollow noreferrer"><code>MODULEENTRY32</code></a> data retrieved from the snapshot. For more information about what a module handle is, see <a href="https://devblogs.microsoft.com/oldnewthing/2004/06/14" rel="nofollow noreferrer">here</a>.</p> <p>Once you have completed the first step, the structure at the base address is the <a href="https://stackoverflow.com/questions/6126980/get-pointer-to-image-dos-header-with-getmodulehandle"><code>IMAGE_DOS_HEADER</code></a>, while this is not documented on MSDN, it has two very important but cryptic fields. The two fields you will need to know are the <code>e_magic</code> field and the <code>e_lfanew</code> field. The <code>e_magic</code> field contains a double word for 32-bit or quadruple for 64-bit that allows you to test if the file being read or your implementation is correctly formatted with the correct value being defined as <code>IMAGE_DOS_SIGNATURE</code>, which is the ASCII-Z string of &quot;MZ\0&quot;. The <code>e_lfanew</code> field contains a <a href="https://stackoverflow.com/questions/2170843/va-virtual-address-rva-relative-virtual-address">relative virtual address</a> which you need to add to the image base you found in step one to calculate the <a href="https://stackoverflow.com/questions/2170843/va-virtual-address-rva-relative-virtual-address">virtual address</a> of the <a href="https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-image_nt_headers32" rel="nofollow noreferrer"><code>IMAGE_NT_HEADERS</code></a> structure.</p> <p>The third step will be to check the first member of the <code>IMAGE_NT_HEADERS</code> to see if it is an actual PE file, this will be defined by the <code>Signature</code> field of the structure, and the defined constant to test for will be <a href="https://web.archive.org/web/20180706112517/http://win32assembly.programminghorizon.com:80/pe-tut2.html" rel="nofollow noreferrer"><code>IMAGE_NT_SIGNATURE</code></a>. This is not typically nessecary, since most Windows versions will be using the PE format of executable file, but it's good practice in order to ensure your code is a bit more robust.</p> <p>Once everything checks out and you have performed steps 1-3, step four will be when you can finally calculate the address of the <a href="https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-image_section_header" rel="nofollow noreferrer"><code>IMAGE_SECTION_HEADER</code></a> structures. The IMAGE_SECTION_HEADER structures are stored as an array in the file, so to obtain the size of the array, you will need to use the <code>NumberOfSections</code> member in the <a href="https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-image_file_header" rel="nofollow noreferrer"><code>IMAGE_FILE_HEADER</code></a> structure which is nested in the <code>IMAGE_NT_HEADERS</code> structure mentioned above.Once you have that value, you may find the virtual address of the first <code>IMAGE_SECTION_HEADER</code> by adding the size of the <code>Signature</code> member of the <code>IMAGE_NT_HEADERS</code> structure, the size of the <code>FileHeader</code> member in the <code>IMAGE_NT_HEADERS</code> structure, and finally the <code>SizeOfOptionalHeader</code> value in the <code>IMAGE_FILE_HEADER</code> structure. The reason you can't simply do a <code>sizeof(</code> <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms680339(v=vs.85).aspx" rel="nofollow noreferrer"><code>IMAGE_OPTIONAL_HEADER</code></a> <code>)</code> for the last value in the formula listed above is because a file on disk <em><strong>will not</strong></em> have the <code>IMAGE_OPTIONAL_HEADER</code>, so to obtain the proper size dynamically, you should do so through the structure member I mentioned earlier.</p> <p>Now you may simply copy the array of <code>IMAGE_SECTION_HEADER</code> structures from memory any way you please. Just remember, that these structures <em>are contigous</em> in memory, so all you need to do is multiply the size of each structure by the number of sections to find the total size of the entire array in memory. After you have calculate that value, it will be trivial to collect the data.</p> <p>For more resources on the PE executable format, see this wonderful article written by Matt Pietrek, <a href="https://docs.microsoft.com/en-us/previous-versions/ms809762%28v=msdn.10%29" rel="nofollow noreferrer"><em>Peering Inside the PE</em></a>. You may also take a look at the official specification <a href="https://docs.microsoft.com/en-us/windows/win32/debug/pe-format" rel="nofollow noreferrer">here</a>.</p>
6077
2014-08-15T14:53:23.377
<p>I'm implementing a software for performing some PE classification. Among the features values I'm gathering from each PE are, the <strong>amount of sections</strong>, the <strong>name of sections</strong>, <strong>image section headers</strong>.</p> <p>I have been reading about <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms680198(v=vs.85).aspx" rel="nofollow noreferrer">ImageHlp Structures</a>. But there is no example on how to get those struct initialized from a file/path_to_a_file you pass. I'm specially interested in the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms680341(v=vs.85).aspx" rel="nofollow noreferrer">IMAGE_SECTION_HEADER</a> structure.</p> <p>How can I get the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms680341(v=vs.85).aspx" rel="nofollow noreferrer">IMAGE_SECTION_HEADER</a>s form an executable file programatically?</p>
Get section's names and headers for a file using C++
|binary-analysis|c++|pe|
<p>When compiling C/C++ code, you can also detect the ARM/thumb status for a function by looking at the symbol table. The lowest bit of the address is set to 1 for Thumb and 0 for ARM instructions. To see this, you can use <code>readelf --symWhen using</code>objdump -t<code>and</code>readelf`, though.</p> <pre><code>$ readelf --syms foo.elf |grep strlen$ 4460: 08000195 16 FUNC GLOBAL DEFAULT 2 strlen $ objdump -t foo.elf |grep strlen$ 08000194 g F .text 00000010 strlen </code></pre> <p>Note that the actual address is 8000194 (32-bit aligned), but the symbol table entry (as shown by readelf) says 9000195 (with the LSB set to indicate thumb).</p> <p>This approach will only tell you the ARM/thumb status at the start of a function, to see any transitions inside a function you will still need to look at the <code>$t</code> and <code>$a</code> symbols as documented in other answers.</p> <p>The meaning of this LSB is defined in the <a href="http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044e/IHI0044E_aaelf.pdf" rel="nofollow noreferrer">ARM ELF ABI</a>:</p> <blockquote> <p>5.5.3 Symbol Values</p> <p>In addition to the normal rules for symbol values the following rules shall also apply to symbols of type STT_FUNC:</p> <ul> <li>If the symbol addresses an Arm instruction, its value is the address of the instruction (in a relocatable object, the offset of the instruction from the start of the section containing it).</li> <li>If the symbol addresses a Thumb instruction, its value is the address of the instruction with bit zero set (in a relocatable object, the section offset with bit zero set).</li> <li>For the purposes of relocation the value used shall be the address of the instruction (st_value &amp; ~1).</li> </ul> <p>Note: This allows a linker to distinguish Arm and Thumb code symbols without having to refer to the map. An Arm symbol will always have an even value, while a Thumb symbol will always have an odd value. However, a linker should strip the discriminating bit from the value before using it for relocation.</p> </blockquote>
6080
2014-08-15T22:18:37.817
<p>I try to build a small disassembler for ARM, and I would like to know how do <code>objdump</code> manage to sort out the normal mode instructions (32-bits instruction wide) from the thumb mode instructions (16-bits instruction wide) without having to look at the <code>t</code> flag in the CPSR.</p> <p>But first, let us build a small example and make some experiments on it. </p> <p>I wrote this small piece of ARM assembly (<code>gas</code> syntax) as basis example:</p> <pre><code>.arm mov fp, #0 moveq r1, r0 .thumb mov r0, #0 mov fp, r0 </code></pre> <p>Then, I cross-compiled it like this:</p> <pre><code>$&gt; arm-none-eabi-gcc -Wall -Wextra -mlittle-endian -c -o arm_sample arm_sample.s </code></pre> <p>And, here is the output of <code>objdump</code> on the ARM object file:</p> <pre><code>$&gt; objdump -d ./arm32_mov ./arm32_mov: file format elf32-littlearm Disassembly of section .text: 00000000 &lt;.text&gt;: 0: e3a0b000 mov fp, #0 4: 01a01000 moveq r1, r0 8: 2000 movs r0, #0 a: 4683 mov fp, r0 </code></pre> <p>But, when I run my tool, I get:</p> <pre><code> warning: decoder says at (0x8,0):'strmi r2, [r3], r0' : Unknown mnemonic 0: 00 b0 a0 e3 mov fp, #0 4: 00 10 a0 01 moveq r1, r0 8: ... </code></pre> <p>My tool is based on <code>libopcodes</code> (exactly like <code>objdump</code>), so the third instruction is just interpreted as still in 32-bits mode and the two thumb mode instructions are just interpreted as one 32-bits instruction which gives <code>strmi r2, [r3], r0</code>.</p> <p>My question is that I don't understand how <code>objdump</code> knows that there is a switch between normal mode to thumb mode. Before discovering this, I thought that this information was only available at execution time though the value of the <code>t</code> flag in the CPSR status register.</p> <p>I tried to look at the code of <code>objdump</code> but, I didn't see any architecture dependent cases to treat the case of the ARM thumb mode. So, this is still a mystery to me... </p> <p>Any suggestion is welcome !</p> <p><strong>EDIT</strong></p> <p>In fact, I worked on an object file (compiled with <code>-c</code> option), so there is not so much symbols. But, here is a more detailed output obtained through <code>objdump</code>:</p> <pre><code>$&gt; objdump -x ./arm32_mov ./arm32_mov: file format elf32-littlearm ./arm32_mov architecture: armv4t, flags 0x00000010: HAS_SYMS start address 0x00000000 private flags = 5000000: [Version5 EABI] Sections: Idx Name Size VMA LMA File off Algn 0 .text 0000000c 00000000 00000000 00000034 2**2 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .data 00000000 00000000 00000000 00000040 2**0 CONTENTS, ALLOC, LOAD, DATA 2 .bss 00000000 00000000 00000000 00000040 2**0 ALLOC 3 .ARM.attributes 00000016 00000000 00000000 00000040 2**0 CONTENTS, READONLY SYMBOL TABLE: 00000000 l d .text 00000000 .text 00000000 l d .data 00000000 .data 00000000 l d .bss 00000000 .bss 00000000 l d .ARM.attributes 00000000 .ARM.attributes </code></pre> <p>And, here is the output of <code>readelf</code>:</p> <pre><code>$&gt; readelf -a ./arm32_mov ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: REL (Relocatable file) Machine: ARM Version: 0x1 Entry point address: 0x0 Start of program headers: 0 (bytes into file) Start of section headers: 148 (bytes into file) Flags: 0x5000000, Version5 EABI Size of this header: 52 (bytes) Size of program headers: 0 (bytes) Number of program headers: 0 Size of section headers: 40 (bytes) Number of section headers: 8 Section header string table index: 5 Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 00000000 000034 00000c 00 AX 0 0 4 [ 2] .data PROGBITS 00000000 000040 000000 00 WA 0 0 1 [ 3] .bss NOBITS 00000000 000040 000000 00 WA 0 0 1 [ 4] .ARM.attributes ARM_ATTRIBUTES 00000000 000040 000016 00 0 0 1 [ 5] .shstrtab STRTAB 00000000 000056 00003c 00 0 0 1 [ 6] .symtab SYMTAB 00000000 0001d4 000070 10 7 7 4 [ 7] .strtab STRTAB 00000000 000244 000007 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings) I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific) There are no section groups in this file. There are no program headers in this file. There are no relocations in this file. There are no unwind sections in this file. Symbol table '.symtab' contains 7 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 SECTION LOCAL DEFAULT 1 2: 00000000 0 SECTION LOCAL DEFAULT 2 3: 00000000 0 SECTION LOCAL DEFAULT 3 4: 00000000 0 NOTYPE LOCAL DEFAULT 1 $a 5: 00000008 0 NOTYPE LOCAL DEFAULT 1 $t 6: 00000000 0 SECTION LOCAL DEFAULT 4 No version information found in this file. Attribute Section: aeabi File Attributes Tag_CPU_arch: v4T Tag_ARM_ISA_use: Yes Tag_THUMB_ISA_use: Thumb-1 </code></pre> <p><strong>SOLUTION (Ian Cook)</strong></p> <pre><code>$ objdump --syms --special-syms ./arm32_mov ./arm32_mov: file format elf32-littlearm SYMBOL TABLE: 00000000 l d .text 00000000 .text 00000000 l d .data 00000000 .data 00000000 l d .bss 00000000 .bss 00000000 l .text 00000000 $a &lt;-- ARM code 00000008 l .text 00000000 $t &lt;-- Thumb code 00000000 l d .ARM.attributes 00000000 .ARM.attributes </code></pre> <p>Just to be sure, I interleaved arm code, thumb code and arm code again. Here is the dump:</p> <pre><code>$&gt; objdump --syms --special-syms ./arm32_mov ./arm32_mov: file format elf32-littlearm SYMBOL TABLE: 00000000 l d .text 00000000 .text 00000000 l d .data 00000000 .data 00000000 l d .bss 00000000 .bss 00000000 l .text 00000000 $a 00000008 l .text 00000000 $t 0000000c l .text 00000000 $a 00000000 l d .ARM.attributes 00000000 .ARM.attributes </code></pre> <p>You can see that the ARM symbol is present twice at <code>0x0</code> and <code>0xc</code> and are surrounding the thumb symbol.</p>
How to detect thumb mode in ARM disassembly?
|disassembly|assembly|arm|
<p>plb.exe is designed for OMF libraries (primarily used for 16 bit Borland compilers). What you probably want is pcf.exe, which parses COFF libraries commonly used in 32 bit windows.</p>
6089
2014-08-17T14:33:16.650
<p>I'm trying to create a .sig file for sqlite3. I downloaded the source code from the website, compiled it into a .lib (smoothly), and this is what I get when I try to turn it into a .pat file:</p> <pre><code>plb.exe -v sqlite.lib sqlite.lib: invalid module at offset 143146. Skipping. sqlite.lib: invalid module at offset 2587742. Skipping. sqlite.lib: skipped 2, total 2 </code></pre> <p>The resulting .pat file is empty and I cannot proceed to create the final file with sigmake.</p> <p>Google doesn't seem to indicate that anyone has ever had an "invalid module at offset" problem in the entire world, so I'm guessing this is pretty unique. I'm stuck. Help?</p>
Unable to create FLIRT signature for IDA
|ida|flirt-signatures|
<p>Several years ago i wrote <a href="http://nah6.com/~itsme/cvs-xdadevtools/ida/idcscripts/swapinsn.idc" rel="nofollow">swapinsn.idc</a> to do this for ARM code. It will rotate a sequence of insns up or down, and fix any relative jumps in that range.</p> <p>Note that contrary to the comments in the script, i never actually added x86 support.</p> <p>For convenience i added hotkey functions <code>HK_ExchangeDown</code> and <code>HK_ExchangeUp</code> as defined in <a href="http://nah6.com/~itsme/cvs-xdadevtools/ida/idcscripts/hotkeys.idc" rel="nofollow">hotkeys.idc</a>. So in can select a range of instructions, type shift-x to move the last selected insn up, and the rest down.</p>
6096
2014-08-19T12:01:33.837
<p>I'm disassembling an old (1996) game, that has been compiled with the Watcom 386 compiler. This compiler seems to aggressively reorder instructions to make better use of the processor pipeline, as seen in this chunk of assembly:</p> <p><img src="https://i.stack.imgur.com/RqNJ3.png" alt="enter image description here"></p> <p>The instructions marked with a red dot set up the parameters for the next call; the instructions with a blue dot finish the initialization of the object returned from the previous call. Rearranging them makes the assembly much easier to read:</p> <pre><code>... call ClassAlloc13680_0FAh mov edx, [eax] mov [edx+Class180F4.WidgetInputHandler], offset gblHandleTransportDestinationAndCheckForPassengersSpace mov edx, [eax] mov [edx+Class13680.Paint???], offset ClassVehicleManager__PaintForSomeWidget mov dword_A4D88, eax mov eax, [eax] mov [eax+Class10B8C.MouseInputHandler], offset ClassVehicleManager__MouseInputHandler push 0 push 2 push 0 push 4Eh push 5Bh mov ebx, 5Ch mov ecx, 21h mov edx, ebp mov eax, ebp call ClassAlloc13680_0FAh push 0 push 2 ... </code></pre> <p>(Note that i moved the <code>mov reg, xxh</code> instructions even further down, because the compiler's calling convention is ax-dx-cx-bx-stack, so i can see the order of arguments here as well)</p> <p>Is there a way to accomplish this in IDA? I'm not asking for an algorithm to automatically determine which instructions should be "red" and which should be "blue", and i don't want to patch the original binary file, i'd just like to manually re-arrange instructions in the ida database.</p> <p>Or is there another way to improve readability of this kind of code in IDA?</p>
Rearrange instructions in an ida database?
|ida|assembly|
<p>An NTFS file can have <a href="http://ntfs.com/ntfs-multiple.htm" rel="nofollow">multiple data streams</a>. $DATA is the name of the default stream.</p> <p>From <a href="http://en.wikipedia.org/wiki/Fork_%28file_system%29" rel="nofollow">Wikipedia</a>: Internet explorer, (and, according to the german wikipedia, newer versions of Firefox), use the Zone.Identifier stream to store information from where you downloaded the file. You might have seen the "File Origin: downloaded from internet" message in a UAC prompt. </p> <p>You can edit the Zone.Identifier data with notepad. For example, on one of your files that have this attribute, run <code>notepad myfile.exe:Zone.Identifier</code>. This should give you something like</p> <pre><code>[ZoneTransfer] ZoneId=3 </code></pre> <p>Change the 3 to a 0, then save from notepad. Next time you run the file as adminstrator, the "Origin: Internet" message will change to "Origin: this computer's hard disk".</p> <p>The answer to your question "why is it absent on some other files" is - only NTFS supports this. If you copy a file to a USB stick, SD card, or network storage, the file will lose its stream; when you copy it back, it doesn't magically gain the stream back. So only files that you downloaded via internet explorer (and possibly other browsers) on your NTFS hard disk will have it. Or, of course, files in which you created the stream yourself, like in <code>echo "this is a fake" &gt; myfile.exe:Zone.Identifier</code>.</p> <p>Of course, the only thing this has to do with reverse engineering is that Ollydbg is one of the few tools that tell you if a file as alternate data streams.</p>
6097
2014-08-19T12:34:59.847
<p>What is the usage of "Stream:" portion in View==>File==>Open File window? For some files it shows <pre>main<br>:Zone.Identifier:$DATA</pre> what's the meaning of this?</p>
OllyDbg2: What is the meaning of Stream in File View Window?
|ollydbg|
<p>Your library might get loaded to a location that's completely different from the one it wants to be loaded at, i.e. the address in the header, due to <a href="http://en.wikipedia.org/wiki/Address_space_layout_randomization" rel="nofollow">ASLR</a>.</p> <p>Also, when loading a DLL, Ollydbg doesn't load the DLL directly; instead, it uses <code>loaddll.exe</code>. Which means, it starts the executable, but the breakpoint it sets is <em>before</em> <code>loaddll</code> has a chance to, well, load the DLL.</p> <p>Try the following:</p> <ul> <li>Set a breakpoint on <code>LoadLibraryA</code> : right click in CPU Window - Go To - Expression - <code>LoadLibraryA</code> - Press <kbd>F2</kbd>;</li> <li>Repeat the same with LoadLibraryW (the A version should be sufficient, just to make sure);</li> <li>Run the program;</li> <li>Once your breakpoint is it, press <kbd>CTRL</kbd>-<kbd>F9</kbd> (execute till return);</li> <li>If your DLL depends on others, you'll hit one of your breakpoints again; else you'll hit the breakpoint at the <code>RET</code> instruction. Don't worry, in either case, your DLL will be loaded;</li> <li>Use View->Memory or View->Executable Modules to learn where your DLL was actually loaded. This may be the same address that DLL Export Viewer shows you, but often, it will be different (address conflicts between two DLLs, in which case one has to be relocated, or ASLR, as above);</li> <li>Only if the addresses match: Right Click -> GoTo -> Expression -> <code>0x12345678</code> or whatever address you want to see;</li> <li>No matter if they match or not: Right Click -> GoTo -> Expression -> (Function name) will scroll to that function.</li> </ul> <p>The reason for your '<em>disappearing</em>' instruction is that it's the middle of another instruction. Consider this function start:</p> <pre><code>10001280 &gt; 53 PUSH EBX 10001281 56 PUSH ESI 10001282 57 PUSH EDI 10001283 8B7C24 10 MOV EDI,DWORD PTR SS:[ESP+10] 10001287 8BF1 MOV ESI,ECX 10001289 3BF7 CMP ESI,EDI 1000128B 0F94C3 SETE BL 1000128E 84DB TEST BL,BL 10001290 75 32 JNZ SHORT 100012C4 </code></pre> <p>The byte at <code>10001284</code>, <code>0x7c</code>, is part of the instruction at <code>1001283</code>. But if you disassemble from <code>10001284</code>,</p> <pre><code>10001284 7C 24 JL SHORT 100012AA 10001286 108B F13BF70F ADC BYTE PTR DS:[EBX+FF73BF1],CL 1000128C 94 XCHG EAX,ESP 1000128D C3 RETN 1000128E 84DB TEST BL,BL 10001290 75 32 JNZ SHORT 100012C4 </code></pre> <p>The wrong bytes get interpreted as instructions. Once you scroll up a few rows, Ollydbg syncs correctly again - and shows the '<em>real</em>' instructions.</p>
6104
2014-08-21T07:21:12.420
<p>Being rather new to the concept of RE, I wanted to try and take a look at the assembly code in one DLL that I know exports some functions.</p> <p>First, I used this tool - <a href="http://www.nirsoft.net/utils/dll_export_viewer.html" rel="nofollow">http://www.nirsoft.net/utils/dll_export_viewer.html</a> - to obtain a list of exports within said DLL. These are some of the functions:</p> <pre><code>GI_Call 0x100590a7 0x000590a7 2 (0x2) mydll.dll I:\test\mydll.dll Exported Function GI_CleanReturnStack 0x10058eae 0x00058eae 3 (0x3) mydll.dll I:\test\mydll.dll Exported Function GI_Cmd_Argc 0x10058bd4 0x00058bd4 4 (0x4) mydll.dll I:\test\mydll.dll Exported Function GI_Cmd_Argc_sv 0x10059593 0x00059593 5 (0x5) mydll.dll I:\test\mydll.dll Exported Function </code></pre> <p>When I, however, load the DLL up in OllyDbg and browse to any of these addresses, I get instructions that don't really resemble a beginning of a function, for example GI_Call:</p> <pre><code>100590A7 10E9 ADC CL,CH 100590A9 CE INTO 100590AA FC CLD 100590AB FFFF ??? ; Unknown command 100590AD FF75 10 PUSH DWORD PTR SS:[EBP+10] 100590B0 8D45 FC LEA EAX,DWORD PTR SS:[EBP-4] 100590B3 50 PUSH EAX 100590B4 57 PUSH EDI </code></pre> <p>What's even more puzzling is that once I scroll up/down, the code actually changes - there's no</p> <pre><code>100590A7 10E9 ADC CL,CH </code></pre> <p>anymore, it changes to a completely different instruction, also that address is gone.</p> <p>Am I doing something wrong? Or is the DLL possibly encrypted? Though if it is, how could DLL Export Viewer dump the exports so easily?</p>
Viewing an exported DLL function in OllyDbg - garbage code
|disassembly|ollydbg|dll|functions|
<p>The most likely reason why your breakpoint didn't get hit is because the protected file removed it.</p> <p><strong>Edit</strong>: If the breakpoint was hardware-based, then the protected file can use <code>GetThreadContext()</code>, erase the DR entries, <code>SetThreadContext()</code>. If the breakpoint was page-protection-based, then the protected file can use <code>VirtualProtect()</code>.</p>
6124
2014-08-26T02:36:57.213
<p>I am currently battling this protection on an 32-bit executable. </p> <p>At some point during it's runtime, the protection gets the address of <code>DbgUiRemoteBreakin</code> and writes a <code>JMP</code> to <code>ExitProcess</code> as an anti-attach technique. I decided to place a memory breakpoint on write(I also tried access) on that location figuring at the very least I'd find out what piece of code alters the code. Upon setting the breakpoint I hit <kbd>F9</kbd> only for my memory bp to never be triggered, I tried multiple times. The code was altered, but my memory bp was not triggered. This is the first time that a memory breakpoint was not triggered for me. I am puzzled as to why this has happened. My only guess is that <code>DbgUiRemoteBreakin</code> is located in <em>ntdll.dll</em> and that is why guard pages don't work there. There were also instances where I had a crash when I set a memory bp on that function.</p> <p>However I am hoping somebody has encountered this and can explain more in depth. My ollydbg version is 1.10.</p>
Why was my memory breakpoint not triggered in OllyDbg?
|ollydbg|pe|anti-debugging|protection|
<p>I know its late answer but for future users: To solve this you need to go to threads window, and then</p> <p>right mouse button->resume all threads</p>
6140
2014-08-29T21:08:24.193
<p>In my OllyDbg v1.10, when I attempt to attach the debugger to a running process, Olly behaves as if it was successful, but the process is frozen (I'm unable to bring the window back up). I've tried switching to the main module, hitting F9 - still nothing, the process simply halts ("Paused" in Olly). I've found this issue described by a user on some forum, but it had remained unresolved as others had trouble reproducing it.</p> <p>I've tried this for MS Notepad, Calc, regedit and a propetriary 3rd party application, and the result is the same everywhere.</p> <p>This does not hold true for Olly 2.0 - that version behaves as expected, simply attaches to the process and lets me explore it.</p> <p>My OS is a 32-bit Windows 7 Ultimate.</p>
OllyDbg 1.10 - attaching to running process suspends it indefinitely
|ollydbg|
<h1>PIN_AddSyscallEntryFunction</h1> <p>Why not just use <code>PIN_AddSyscallEntryFunction</code>? This is an ABI-agnostic way of doing things, that lets you use <code>PIN_GetSyscallArgument</code> and related functions rather than manually inspecting the stack and register context.</p> <h1>INS_IsInterrupt</h1> <p>You could also use <code>INS_IsInterrupt</code> at instrumentation time to gather the information at analysis time. Note that this won't catch any systemm calls made via the <code>syscall</code> or <code>sysenter</code> instructions.</p> <h1>Examples</h1> <p>As a simple example, if you look at the file <a href="https://github.com/JonathanSalwan/stuffz/blob/master/binary_analysis_with_ins_counts/inscount0.cpp#L48" rel="nofollow"><code>inscount0.cpp</code></a> that comes with Pin, if you add the following check, you'll only instrument syscalls.</p> <h3>INS_IsInterrupt</h3> <p>In <code>inscount0.cpp</code>, change the routines as shown below. The module will now count the number of <code>int</code> instructions executed, rather than the total number of instructions executed.</p> <pre><code>VOID Instruction(INS ins, VOID *v) { if(INS_IsSyscall(ins)) { INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)docount, IARG_END); } } </code></pre> <p>Now all syscall instructions will be counted. You can use the standard <code>INS_InsertCall</code> arguments to inspect the stack or register context.</p> <h3>PIN_AddSyscallEntryFunction</h3> <p>Add this function before <code>main</code></p> <pre><code>void OnSyscall(THREADID threadIndex, CONTEXT *ctxt, SYSCALL_STANDARD std, VOID *v) { printf("Made syscall #%i\n", PIN_GetSyscallNumber(ctxt, std)); } </code></pre> <p>and add this line to <code>main</code> before <code>PIN_StartProgram</code>.</p> <pre><code>PIN_AddSyscallEntryFunction(OnSyscall, 0); </code></pre>
6144
2014-08-31T15:36:32.630
<p>I wrote this small pintool that tries to record the number of <code>int 0x80</code> instructions executed. I did this roughly as follows :-</p> <p><code>xed_iclass_enum_t iclass = static_cast&lt;xed_iclass_enum_t&gt;(INS_Opcode(ins));</code></p> <p>I then compare iclass against XED_ICLASS_INT and print out the EIP if found. I'm doing this on a statically compiled test binary that :-</p> <pre><code>1. Prints hello world 2. Makes a call to mprotect </code></pre> <p>However, the number of <code>int 0x80</code> instructions encountered is just one. Is there something obvious I'm doing wrong? I tried using XED_ICLASS_SYSCALL too but that did not help.</p>
Tracing int 0x80 instructions using PIN
|instrumentation|
<p>On modern Linux systems, a syscall stub (<code>vdso</code>) is used to invoke the actual syscall. This is done so that the application binary does not need to know anything about the host CPU, and what mechanism is best or fastest for the CPU.</p> <p>This can be seen from within GDB or via <code>ldd</code>.</p> <pre><code>ldd /bin/bash linux-vdso.so.1 =&gt; (0x00007fff07fc3000) libtinfo.so.5 =&gt; /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f65e336e000) libdl.so.2 =&gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f65e316a000) libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007f65e2da3000) /lib64/ld-linux-x86-64.so.2 (0x00007f65e35b6000) </code></pre> <p>You can easily dump out the instruction being executed with Pin via printing the return value of <code>INS_Disassemble</code>. You should see that it's actually a <code>syscall</code> instruction or similar.</p> <p>Regarding the best mechanism for determining the source of a call to the VDSO, checking the top of the stack at a routine entry will give you its return address. This will be a few bytes <em>after</em> the <code>call</code> instruction. Additionally, you'd have to whitelist the explicit address which is in the <code>vdso</code>, as not all <code>int 0x80</code> instructions will be immediately after a call.</p>
6146
2014-08-31T17:54:17.467
<p>I have a statically compiled test binary compiled as :-</p> <pre><code>$ cat &gt; test.c #include&lt;stdio.h&gt; int main() { printf("adsf"); mprotect(0x8048000, 0x100, 0x7); } $ gcc -o test test.c -static </code></pre> <p>I use the strace.so pintool and get the following output:-</p> <pre><code>0xb77c0419: 122(0xbfa1a72a, 0xb77c0000, 0x0, 0x0, 0x8049630, 0xbfa1a6ec)returns: 0x0 0xb77c0419: 45(0x0, 0x840, 0x27, 0xd40, 0x28, 0xbfa1a868)returns: 0x9fda000 0xb77c0419: 45(0x9fdad40, 0x840, 0x9fda000, 0x9fdad40, 0x28, 0xbfa1a868)returns: 0x9fdad40 0x80493b9: 243(0xbfa1a8c0, 0x0, 0x4, 0x4, 0x28, 0x40)returns: 0x0 0xb77c0419: 45(0x9ffbd40, 0x21000, 0x21000, 0x9ffbd40, 0x0, 0xbfa1a728)returns: 0x9ffbd40 0xb77c0419: 45(0x9ffc000, 0x2c0, 0x21000, 0x9ffc000, 0x0, 0xbfa1a728)returns: 0x9ffc000 0xb77c0419: 197(0x1, 0xbfa1a210, 0xbfa1a210, 0x2000, 0x2000, 0xbfa1a1b8)returns: 0x0 0xb77c0419: 192(0x0, 0x1000, 0x3, 0x22, 0xffffffff, 0xbfa1a1cc)returns: 0xb60b6000 0xb77c0419: 125(0x8048000, 0x100, 0x7, 0x0, 0x8049630, 0xbfa1a8d8)returns: 0x0 0xb77c0419: 4(0x1, 0xb60b6000, 0x4, 0x80ef6a0, 0x4, 0xbfa1a778)returns: 0x4 0xb77c0419: 252(0x0, 0x0, 0x80f0d04, 0x0, 0x80ef06c, 0xbfa1a8ac)#eof </code></pre> <p>We can see that the addresses shown at the left(the IP) have repeating values. Also they don't seem to be addresses in the text segment. I'd like to be able to view the addresses at which the system calls are made.</p> <p>Why does this happen? The code for the strace pintool can be found <a href="https://svn.mcs.anl.gov/repos/performance/Gwalp/gwalpsite/pin/source/tools/ManualExamples/strace.cpp" rel="nofollow">here</a>.</p> <p>[EDIT] Checking in gdb I understand that this happens because the call goes via a common "int 0x80" instruction. As a result, multiple system calls seem to be made from the same address. Hence, it seems like I'd have to read the 4 bytes from the top of the stack to find out which instruction is trying to make the system call. Are there any better ways to do this?</p>
IPs shown by the strace.so pintool
|instrumentation|
<p>This is 64-bit math. The compiler has to do the addition in two steps because the processor can only work 32 bits at a time. And carry has to be propagated from the low addition to the high one - same way when you do addition of multiple-digit numbers on paper.</p> <p>Here's what the current version of the decompiler (1.7) produces (after fixing the function prototype):</p> <pre><code>result = sub5D0500(time - 116444736000000000i64, 10000000i64); </code></pre> <p>And (just a guess) if you rename <code>sub5D0500</code> to <code>__alldiv</code> (compiler helper function for 64-bit division), it becomes:</p> <pre><code>result = (time - 116444736000000000i64) / 10000000; </code></pre> <p>Apparently you're looking at MSVC's <code>_time64</code> implementation. From <code>time64.c</code>:</p> <pre><code>/* * Number of 100 nanosecond units from 1/1/1601 to 1/1/1970 */ #define EPOCH_BIAS 116444736000000000i64 [...] __time64_t __cdecl _time64 ( __time64_t *timeptr ) { __time64_t tim; FT nt_time; GetSystemTimeAsFileTime( &amp;(nt_time.ft_struct) ); tim = (__time64_t)((nt_time.ft_scalar - EPOCH_BIAS) / 10000000i64); if (timeptr) *timeptr = tim; /* store time if requested */ return tim; } </code></pre>
6156
2014-09-02T02:25:33.897
<p>I have this dissassembled routine from an executable but I am having troubles to translate it to C#.</p> <pre><code>.text:005C9290 ; =============== S U B R O U T I N E ======================================= .text:005C9290 .text:005C9290 ; Attributes: bp-based frame .text:005C9290 .text:005C9290 sub_5C9290 proc near ; CODE XREF: .text:00574256p .text:005C9290 ; sub_5ACC50+68p ... .text:005C9290 .text:005C9290 SystemTimeAsFileTime= _FILETIME ptr -8 .text:005C9290 arg_0 = dword ptr 8 .text:005C9290 .text:005C9290 push ebp .text:005C9291 mov ebp, esp .text:005C9293 push ecx .text:005C9294 push ecx .text:005C9295 lea eax, [ebp+SystemTimeAsFileTime] .text:005C9298 push eax ; lpSystemTimeAsFileTime .text:005C9299 call ds:GetSystemTimeAsFileTime .text:005C929F mov eax, [ebp+SystemTimeAsFileTime.dwLowDateTime] .text:005C92A2 mov ecx, [ebp+SystemTimeAsFileTime.dwHighDateTime] .text:005C92A5 push 0 .text:005C92A7 add eax, 2AC18000h .text:005C92AC push offset unk_989680 .text:005C92B1 adc ecx, 0FE624E21h .text:005C92B7 push ecx .text:005C92B8 push eax .text:005C92B9 call sub_5D0500 .text:005C92BE mov ecx, [ebp+arg_0] .text:005C92C1 test ecx, ecx .text:005C92C3 jz short locret_5C92C7 .text:005C92C5 mov [ecx], eax .text:005C92C7 .text:005C92C7 locret_5C92C7: ; CODE XREF: sub_5C9290+33j .text:005C92C7 leave .text:005C92C8 retn .text:005C92C8 sub_5C9290 endp .text:005C92C8 .text:005C92C9 </code></pre> <p>However, I have this pseudo-code from this function generated by IDA Pro:</p> <pre><code>__int64 __cdecl sub_5C9290(int a1) { __int64 result; // qax@1 unsigned __int64 v2; // ST00_8@1 struct _FILETIME SystemTimeAsFileTime; // [sp+0h] [bp-8h]@1 GetSystemTimeAsFileTime(&amp;SystemTimeAsFileTime); HIDWORD(v2) = ((_DWORD)SystemTimeAsFileTime.dwLowDateTime &gt;= 0xD53E8000u) + SystemTimeAsFileTime.dwHighDateTime - 27111903; LODWORD(v2) = SystemTimeAsFileTime.dwLowDateTime + 717324288; result = sub_5D0500(v2, (unsigned int)&amp;unk_989680, 0); if ( a1 ) *(_DWORD *)a1 = result; return result; } </code></pre> <p>One problems is that code won't compile, this code doesn't make sense:</p> <pre><code>HIDWORD(v2) = ((_DWORD)SystemTimeAsFileTime.dwLowDateTime &gt;= 0xD53E8000u) + SystemTimeAsFileTime.dwHighDateTime - 27111903; </code></pre> <p>Also one problem is the <code>ADC</code> command which all I can find is that it is exactly as <code>ADD</code> but it also adds the <code>CARRY FLAG</code> to the result, but I can't find any ways to reproduce this command in C#. And what about all those <code>HIDWORD</code> and <code>LODWORD</code> macros?</p>
Convert assembly ADC to C#
|ida|disassembly|c#|
<p>Looking at the website for the software vendor, <a href="http://www.meyetech.com/support/support98.html" rel="nofollow">it recommends</a> that the DVR on the other end of the connection be set to "Substream, CIF or QCIF at 6-10 FPS". Those refer to the <a href="http://en.wikipedia.org/wiki/Common_Intermediate_Format" rel="nofollow">"Common Intermediate Format"</a> and "Quarter Common Intermediate Format" respectively. They are defined within the <a href="http://www.itu.int/rec/T-REC-H.261-199303-I/en" rel="nofollow">"H.261 Video codec for audiovisual services at p x 64 kbit/s"</a> standard, so you may find sufficient detail within those documents (which are available for free) to be able to start making some intelligent guesses as to how to decode this particular protocol. </p> <p>With that said, Wireshark, as least as of September 2014, does not support H.261 decoding. Perhaps you could add it.</p>
6160
2014-09-02T18:54:32.630
<p>Is it possible to identify a protocol in a pcap file? I have a file which is a capture of data going between my phone and an IP camera, and I'd like to identify the protocol. I am using the app "MEye" to view the camera, which provides no hints of the protocol used.</p> <p>I have tried googling the headers in some of the packets, but to no avail.</p> <p>The pcap file can be found <a href="http://a.pomf.se/vdplhi.pcap" rel="nofollow">here</a>.</p> <p>Is it possible to identify the protocol at all?</p>
Identifying protocol in a pcap file?
|sniffing|networking|protocol|packet|
<p>You're misunderstanding the use of the keyword. As the comment on your questions said, WINAPI is the calling convention for a function. WINAPI is #define'd to __stdcall which specifies how the stack is managed in relation to that function, which you can see documented on MSDN <a href="http://msdn.microsoft.com/en-us/library/zxk0tw93.aspx" rel="nofollow">here</a>. That article gives you a good overview of what it does and how it would get used in the header file. </p> <p>It's common for the calling convention to not be explicitly stated for CRT functions on Windows; but that's just in the documentation and doesn't mean the calling convention doesn't need to be declared similarly. Most functions (on x86) will use __stdcall. The most common exception is the printf() family of functions which use the cdecl calling convention. This has more to do with the history of how x86 was developed than any particular design choices.</p> <p>Most constants, WINAPI et al, can be found somewhere on MSDN or if you have Visual Studio by hitting F12.</p> <p>Now as far as a more general answer to what I take your question to be, as far as how/why you might see certain function calls in a particular sample, the short answer is that Windows provides both the standard C library calls and its own versions of the APIs. In this case, the send() function is defined in Winsock2.h and the function itself is in Ws2_32.lib (also available on that MSDN page you linked). However, what you might call the "Windows API version" of this function is also found in the same .h and .lib file: WSASend(), which is documented <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms742203(v=vs.85).aspx" rel="nofollow">here</a>.</p> <p>You can see by the two articles on MSDN these functions are almost identical, and if you look at the disassmebly for both of them you'd see that WSASend() and send() are almost the exact same function. But Windows supports both so if you learn on Unix or just using the standard C library you can write the same code on windows.</p> <p>Most of the other CRT functions (fopen, fread, printf) are implemented in the C Runtime Library, msvcrt.dll. They're mostly independent (compared to socket functions all being in Ws2_32.lib).</p>
6165
2014-09-03T21:39:44.333
<p>I try to analyze malware since a few months and by examining the assembly code of a trojan for example, I see sometimes windows functions like <code>ws2_32.send</code> which is the <code>send()</code>-function, etc. That is not a problem to understand, I can go to: </p> <p><a href="http://msdn.microsoft.com/de-de/library/windows/desktop/ms740149%28v=vs.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/de-de/library/windows/desktop/ms740149%28v=vs.85%29.aspx</a></p> <p>and read that, everything is okay. </p> <p>But I ask myself, how the people who writes that code put that function in their code. I mean, can you for example write in a C code the function </p> <pre><code> int send( __in SOCKET s, __in const char *buf, __in int len, __in int flags); </code></pre> <p>and is it then so that the C compiler understands it ? There are some other functions like <code>CopyFileA</code> for example which looks like:</p> <pre><code> BOOL WINAPI CopyFile( _In_ LPCTSTR lpExistingFileName, _In_ LPCTSTR lpNewFileName, _In_ BOOL bFailIfExists ); </code></pre> <p>Here I ask myself how the compiler understand the word <code>"WINAPI"</code> for example and so on.</p> <p>In general, if the people try to write such code to create a trojan, how they make clear that it should be a windows function? </p>
Question about Windows-Functions in malware
|assembly|
<p>Here is a simple video for setting up qemu for ARM. </p> <p><a href="http://www.securitytube.net/video/5818" rel="nofollow">http://www.securitytube.net/video/5818</a></p> <p>Using IDA you can open and disassemble the program fine. Just to debug you will probably get stuck using GDB as you can't run the arm binary in your current environment. </p> <p>Let me know if you have more questions.</p>
6171
2014-09-04T05:26:36.197
<p>I'm newbie, I have a little knowledge of debugging x86 binary. However, I have to work with ARM. I'm getting stuck on install QEMU and can't debug an ARM binary.</p> <p>Thank you a lot for give me tutorials of reversing an example ARM binary.</p>
How to debug ARM binary with IDA pro on Windows?
|ida|arm|qemu|
<p>Most modern IDE's allow you to specify an executable to launch when debugging, you should specify your ida executable. Or otherwise, try to attach to the running IDA process.</p> <p>When you put a breakpoint in the run() function of your plugin, your IDE will stop at run, and you can singlestep, etc from there.</p> <p>Also you if you enable 'break on exception' your IDE will probably figure out if the exception was in your plugin, and load the right source file for you.</p>
6177
2014-09-05T07:31:56.520
<p>I'm building an IDA Pro plugin (not a script) using the C++ SDK. On top of the frustration added by the lack of a proper API documentation, I cannot find a good way to debug my plugin.</p> <p>I've tried printing messages to the output window of IDA Pro. </p> <pre><code>... msg("Everything OK up to point 1\n"); ... msg("Everything OK up to point 2\n"); ... </code></pre> <p>However, whenever my plugin hits an error state, IDA Pro crashes before I get a chance to read the messages that my plug-in printed in the output window.</p> <p>While searching for a solution I stumbled upon the <a href="http://wingware.com/doc/howtos/idapython" rel="noreferrer">Wingware Python IDE</a> which can be used to debug IDAPython. The drawbacks however are that it is not free and I am not developing the plugin in python.</p> <p>One obvious thing to try is writing to a text file instead of writing to the IDA output window. However, that is not handy debugging. Isn't there a better way to debug an IDA Pro plugin built with C++ SDK?</p>
How to debug an IDA Pro plugin built with the C++ IDASDK
|ida|ida-plugin|idapro-sdk|
<p><a href="http://www.dependencywalker.com/">Dependency Walker</a> is your friend.</p> <p>Note that it's almost impossible to find out which libraries/entry points a program uses by static analysis alone, since the strings passed to <code>LoadLibrary</code> and <code>GetProcAddress</code> might be obfuscated, i.e. not visible in the binary. <code>Dependency Walker</code> catches those calls at runtime, which means a) you need to run the program - which may not be advisable if it's known malware - and b) it still might miss something if you don't execute that path of code. But within these restrictions, it's about the best you can get.</p>
6179
2014-09-05T13:29:53.697
<p>I'd like to identify all late-binding calls made by a windows 32 or 64 executable program. I can take a look at the imported functions through the IAT but I'm unable to list the functions called during a program invocation.</p> <p>Is there a way to accomplish this?</p>
List late binding functions
|windows|functions|iat|
<p>I have used "File Monitor" from SteelWorks (I am not associated with this company in any way) on a non-routed Android device and it works fine.</p>
6189
2014-09-06T22:50:28.090
<p>Is there a monitoring tool for Android except <code>logcat</code> which works like Process Monitor in Windows ?<BR> Thanks</p>
How to monitor APK files in Android System
|tools|android|apk|
<p>It is possible to define a function exit as "no return" function. This should fix the problem.</p> <p>To do it you should find exit function, right click on it, choose "edit function" and mark "Does not return" checkbox.</p>
6204
2014-09-09T12:38:07.063
<p>I'm analyzing a MIPS ELF executable with calls to the <code>exit()</code> function, however IDA PRO is not correctly recognizing the end of the block:</p> <p><img src="https://i.stack.imgur.com/9Scq4.png" alt="enter image description here"></p> <ul> <li><p><strong>Question</strong>: Is it possible to remove the blue arrow linking the <code>exit()</code> block with the next one ?</p></li> <li><p><strong>Question</strong>: Is it possible to enhance the disassembly if IDA by specifying exit as a block end ?</p></li> </ul>
Correct IDA PRO Control Flow Graph
|ida|
<p>The open-source IDA Pro script <a href="https://github.com/deresz/funcap" rel="nofollow noreferrer"><strong>funcap</strong></a> does 99% of what you want. I'd recommend using it as a foundation and making some minor tweaks to get it to do exactly what you want.</p> <p><img src="https://i.stack.imgur.com/v4TPU.png" alt="funcap"></p>
6206
2014-09-09T16:02:58.360
<p>Is IDA (or some external plugin) capable of adding comments describing values contained in registers to every branch instruction ?</p> <p>e.g.</p> <pre><code>ADD.W R8, R10, #0x78 MOVS R5, #0 ADD.W R1, R10, #0xE8 STR R1, [SP,#0x1C+var_1C] loc_xxxxxxxx MOV R0, R5 MOV R1, R8 BL sub_xxxxxxxx ; r0 = #0, r1 = R10 + #0x78 </code></pre> <p>where the comment at BL <em>sub_xxxxxxxx</em> would be generated automatically</p>
IDA Pro get register values before branch
|ida-plugin|
<p>See <a href="http://www.sourceware.org/ml/binutils/2004-04/msg00469.html" rel="nofollow">this thread</a>. Basically, they rely on the fact that the order of PLT relocations matches the order of the stubs in <code>.plt</code> section, and the stubs are all of the same size.</p> <p>On some platforms you can also use <code>st_value</code> of the symbol entry in the dynamic symbol table.</p> <p>IDA indeed usually does not rely on the order of symbols/relocations but checks the actual instructions in the stub.</p>
6213
2014-09-10T04:06:24.610
<p>Doing some messing around with ELF (of both the x86 and ARM varieties).</p> <p>Associating symbol names with entries in the <code>.got</code> section is straightforward. Find the <code>.got</code> section, find the relocation section <code>.rel.plt</code>/<code>.rela.plt</code> whose <code>.sh_info</code> contains the index of the <code>.got</code>, and find the symbol section <code>.dynsym</code> that contains the symbol names.</p> <p>Everything lines up nicely between these sections, and I can accurately assign symbol names to entries in the <code>.got</code>. </p> <p>However, I also want names for the stubs in the <code>.plt</code> section. A rough percentage of the time, symbols for the <code>.plt</code> can be inferred based on the ordering of <code>.got</code> symbols, and an offset from the base of the <code>.plt</code> section. For whatever reason, occasionally this is not the case.</p> <p>Binutils <code>objdump</code> can accurately generate them for x86, and IDA can accurately generate them for x86 and ARM (both without <code>-g</code> debugging symbols). How are these generated?</p> <p>In the case of IDA, I could reasonably assume there's some advanced logic going on based on interpretation of the instructions in the <code>.plt</code>, but I know that must not be the case for <code>objdump</code>.</p>
Associating Symbol Names with .PLT Entries
|ida|elf|got|plt|
<p>you can alter the base if you so wish msvc compile drivers with an image base of 0x10000</p> <pre><code>:\&gt;kd -c "!dh acpi;q" -z c:\WINDOWS\system32\drivers\acpi.sys | grep -i image File Type: EXECUTABLE IMAGE 00010000 image base 5.01 image version 2DD80 size of image :\&gt; </code></pre> <p>here is how to alter usermode executables imagebase base must be multiples of 64k if base:0 is used exe will be having an image base of 0x10000 </p> <pre><code>:\&gt;dir /b &amp; type * &amp; cl /nologo /Zi * /link /base:0x200000 &amp; dir /b sysbp.cpp sysbp.cpp #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int main (void) { printf("all the bases belongs to base\n"); exit(0); }sysbp.cpp sysbp.cpp sysbp.exe sysbp.ilk sysbp.obj sysbp.pdb vc100.pdb :\&gt;sysbp.exe all the bases belongs to base :\&gt;cdb -c "q;" sysbp.exe | grep -i modload ModLoad: 00200000 00222000 sysbp.exe ModLoad: 7c900000 7c9b2000 ntdll.dll ModLoad: 7c800000 7c8f6000 C:\WINDOWS\system32\kernel32.dll q :\&gt; </code></pre>
6242
2014-09-15T18:00:31.857
<p>Having stumbled upon this question (and answer): <a href="https://stackoverflow.com/questions/2170843/va-virtual-adress-rva-relative-virtual-address">https://stackoverflow.com/questions/2170843/va-virtual-adress-rva-relative-virtual-address</a> on my quest for understanding Windows' PE format, I'm wondering: why is the default imagebase value 0x400000? Why couldn't we just start at 0? A VA would then be, in all practical purposes, equal to an RVA. </p> <p>I'm clearly missing something, but I've been unable to find a reasonable explanation of this for the last 40 minutes.</p>
windows - Why is the imagebase default 0x400000?
|windows|pe|
<p>The dis-assembler display all the variables as having the same address, which is the function's first command (004014CE push ebp in this case).</p> <p>variable with a <strong>positive</strong> offset is a <em>parameter to the function</em>, where a variable with a <strong>negative</strong> offset is usually a <em>local variable</em>. This is of course not always the case but you can take it as a general rule of thumb.</p>
6252
2014-09-17T12:21:24.520
<p>Im newbie at reverse engineering and I was wondering what is the meaning of declaration <code>var_18 = byte ptr -18</code> and the others like it in the picture.</p> <p><img src="https://i.stack.imgur.com/0Si9w.png" alt="IDA Pro screenshot"></p> <p>I know that <code>byte ptr</code> means it is a pointer to a byte variable, but why does it have negative value. And also why do all of them have the same address?</p>
Assembly variable meaning
|ida|disassembly|
<p>IDA knows that the prototype for the <code>_memset</code> function is <code>_memset(void *, int, size_t)</code>, so it's showing you that the value of <code>eax</code> in <code>push eax</code> is for the <code>void *</code> parameter.</p> <p>However, later on in this function, a pointer to the <code>StartupInfo</code> structure is likely passed to <code>CreateProcess</code>, which is why IDA named it as such.</p> <blockquote> <p>How can eax has the type Startupinfo and void at the same time?</p> </blockquote> <p><code>eax</code> is just a register that holds a value, which in your disassembly above is the address of the <code>StartupInfo</code> structure. Types are high-level concepts, so when handled by <code>_memset</code>, the value of <code>eax</code> is interpreted as a <code>void *</code>, and when it's handled by <code>CreateProcess</code>, it's interpreted as a pointer to a <code>STARTUPINFO</code> structure.</p>
6261
2014-09-19T16:58:54.263
<p>I have the following lines discovered in a piece of code (using IDA PRO) :</p> <pre><code> ... ... push 44h pop edi push edi ; size_t xor esi, esi lea eax, [ebp+StartupInfo] push esi ; int push eax ; void * call _memset ... ... </code></pre> <p>When I saw the line <strong>lea eax, [ebp+StartupInfo]</strong> I thought, okay eax is a pointer to the structure STARTUPINFO. With int esi = 0 or NULL (see the line <strong>xor esi, esi</strong>) and with size_t edi = 44h and by calling memset, they must fill the first 44 bytes of STARTUPINFO (that would be the elements cb, lpReserved,....,wShowWindow).</p> <p>But the line push eax ; void *</p> <p>irritates me. How can eax has the type Startupinfo and void at the same time? </p> <p>After that, I found out that the first parameter of memset()-function must have the type void. And so, the question mark in my mind is now bigger...</p>
Competitive Types
|assembly|struct|
<p>Your best bet is probably <a href="http://www.aspectsecurity.com/tools/javasnoop" rel="nofollow noreferrer">JavaSnoop</a>:</p> <p><img src="https://i.stack.imgur.com/IXzEI.png" alt="JavaSnoop"></p> <p>Source code and binaries available from <a href="https://code.google.com/p/javasnoop/" rel="nofollow noreferrer">here</a>.</p> <p>Presentation and demo video available <a href="http://www.youtube.com/watch?v=ipuSmbxBxKw" rel="nofollow noreferrer">here</a>.</p>
6263
2014-09-19T17:58:45.217
<p>I am facing with a software made in Java. This program is a group of jar called in a flow after the first startup.jar</p> <p>There is a way or method to follow executing and know which class is currently running without inject a log class inside all class files?</p> <p>Thanks</p>
How to "follow"Java software executing
|java|
<p>The code is expecting an exception to occur, which will happen in the absence of a debugger. If a debugger is present, the breakpoint exception will usually be suppressed by the debugger, and execution will continue at either 0x455067 or 0x455068, depending on the debugger.</p> <p>You have two simple choices: one choice is that you could just let execution reach 0x455084 and then change var_1 back to zero (or whatever value that it had originally). What you don't want is for it to have the value of "1".</p> <p>The other choice is to change the byte at 0x455065 from 0xCD to 0xFF (for example) and then let that execute. This sequence will cause an exception to occur, which is really what you want to happen (note that the exception code won't be correct, so you'll need to watch if the code checks for a 0x80000003, and take that code path). The execution will be transferred to the handler at 0x455076, at which point you can change the byte at 0x455065 back to 0xCD (in case the code is self-checking), and then resume debugging.</p>
6268
2014-09-20T19:53:51.657
<p>I'm analyzing a PE file using <code>IDA Pro</code> that is using <code>int 2Dh</code> technique as anti debugging: </p> <pre><code>CODE:00455050 push ebp CODE:00455051 mov ebp, esp CODE:00455053 push ecx CODE:00455054 push ebx CODE:00455055 push esi CODE:00455056 push edi CODE:00455057 xor eax, eax CODE:00455059 push ebp CODE:0045505A push offset loc_455076 CODE:0045505F push dword ptr fs:[eax] CODE:00455062 mov fs:[eax], esp CODE:00455065 int 2Dh ; Windows NT - debugging services: eax = type CODE:00455067 inc eax CODE:00455068 mov [ebp+var_1], 1 CODE:0045506C xor eax, eax CODE:0045506E pop edx CODE:0045506F pop ecx CODE:00455070 pop ecx CODE:00455071 mov fs:[eax], edx CODE:00455074 jmp short loc_455084 </code></pre> <p>How should I config IDA Pro to handle this interrupt/exception in dynamic analyzing?<br> I'm Using the local win32 debugger</p>
Handling INT 2D anti-debugger technique in IDA Pro
|ida|debugging|anti-debugging|
<p>I think it should look like this I am 99.9% feel it's a element shifter something tells me that <code>0x3FFFFFFF</code> is max bounds of a array so it's some compiler thing that it appends to make sure it gets the end of the array.</p> <p>I was wrong <code>0x3FFFFFFF</code> is used to create signed numbers to emulate subtracting by adding. See comment by DCoder</p> <pre><code> if ( ZonePlayerCount &gt; 0 ) { v3 = 0; do { if ( playerPointerList[v3].IPAddressDWORD.S_un.S_un_b.s_b1 == IPAddress &amp;&amp; playerPointerList[v3].Port == Port ) { printf("Connection is broken because same ip/port requested another connection\n"); sub_41CBD0((int)&amp;playerPointerList[v3].encryptionPointer-&gt;ConnectionStatus); Memory = *v5; if ( *v5 ) { DisconnectUser(*v5); free(Memory); } memcpy(&amp;playerPointerList[v3], &amp;playerPointerList[v3 + 1], 4 * (ZonePlayerCount - v3 - 1)); //or memmove(&amp;playerPointerList[v3], &amp;playerPointerList[v3 + 1], (ZonePlayerCount - v3 - 1) * sizeof(&amp;playerPointerList)); --ZonePlayerCount; --v3; } ++v3; } while ( v3 &lt; ZonePlayerCount ); } </code></pre> <p>Let me know if this is wrong, I'll remove the answer. (don't have original source code to compare against).</p> <p>Thought I shouldn't be using <code>memcpy</code> because it may leave junk in memory at the very end but i think that junk does no harm and eventually will be replaced with something useful when the time comes.</p> <p>Although it does seem <code>memmove()</code> is better suited here.</p>
6271
2014-09-21T01:23:54.157
<p>I'm trying to clean up the pseudo code to make it compile and function similar if not exactly the same as the original code.</p> <p>This bit which looks like this appears in various places I'm trying to figure out what it exactly means.</p> <pre><code> if ( ZonePlayerCount &gt; 0 ) { v3 = 0; v4 = 0; v5 = playerPointerList; v6 = &amp;playerPointerList[1]; do { if ( *(unsigned int *)&amp;(*v5)-&gt;IPAddressDWORD.S_un.S_un_b.s_b1 == IPAddress &amp;&amp; (*v5)-&gt;Port == Port ) { printf("Connection is broken because same ip/port requested another connection\n"); sub_41CBD0((int)&amp;(*v5)-&gt;encryptionPointer-&gt;ConnectionStatus); Memory = *v5; if ( *v5 ) { DisconnectUser(*v5); free(Memory); } --ZonePlayerCount; memcpy(v5, v6, 4 * (v4 + ZonePlayerCount)); --v3; v4 -= 0x3FFFFFFFu; v6 = (char *)v6 - 4; --v5; } ++v3; v4 += 0x3FFFFFFFu; v6 = (char *)v6 + 4; ++v5; } while ( v3 &lt; ZonePlayerCount ); } </code></pre> <p>Other places like this..</p> <pre><code> v1 = 0; if ( ArenaArrayLength &gt; v1 ) { v18 = 0; v19 = Arenas; v20 = &amp;Arenas[1]; do { if ( ProcessArena(*v19) ) { if ( (*v19)-&gt;ArenaName[0] ) WriteSubGameLog("Private arena dropped: %s\n", (*v19)-&gt;ArenaName); else WriteSubGameLog("Arena dropped\n"); bufa = *v19; if ( *v19 ) { ShutdownArena(*v19); free(bufa); } --ArenaArrayLength; memcpy(v19, v20, 4 * (v18 + ArenaArrayLength)); --v1; v18 -= 0x3FFFFFFFu; v20 = (char *)v20 - 4; --v19; } ++v1; v18 += 0x3FFFFFFFu; v20 = (char *)v20 + 4; ++v19; } while ( v1 &lt; ArenaArrayLength ); } </code></pre> <p>Assembly for the first piece of pseudo code I provide here.</p> <pre><code>.text:00412D7B mov esi, offset playerPointerList .text:00412D80 mov ebx, (offset playerPointerList+4) .text:00412D85 .text:00412D85 loc_412D85: ; CODE XREF: NewConnectionRequest+C0j .text:00412D85 mov eax, [esi] .text:00412D87 mov ecx, [esp+20h+IPAddress] .text:00412D8B cmp [eax+2F3h], ecx .text:00412D91 jnz short loc_412DFC .text:00412D93 mov dx, [esp+20h+Port] .text:00412D98 cmp [eax+2F7h], dx .text:00412D9F jnz short loc_412DFC .text:00412DA1 push offset aConnectionIsBrok ; "Connection is broken because same ip/port "... .text:00412DA6 call _printf .text:00412DAB mov eax, [esi] .text:00412DAD add esp, 4 .text:00412DB0 mov ecx, [eax+28h] .text:00412DB3 call sub_41CBD0 .text:00412DB8 mov ecx, [esi] ; player .text:00412DBA test ecx, ecx .text:00412DBC mov [esp+20h+Memory], ecx .text:00412DC0 jz short loc_412DD4 .text:00412DC2 call DisconnectUser .text:00412DC7 mov ecx, [esp+20h+Memory] .text:00412DCB push ecx ; Memory .text:00412DCC call ??3@YAXPAX@Z ; operator delete(void *) .text:00412DD1 add esp, 4 .text:00412DD4 .text:00412DD4 loc_412DD4: ; CODE XREF: NewConnectionRequest+70j .text:00412DD4 mov eax, ZonePlayerCount .text:00412DD9 dec eax .text:00412DDA mov ZonePlayerCount, eax .text:00412DDF add eax, edi .text:00412DE1 shl eax, 2 .text:00412DE4 push eax ; Size .text:00412DE5 push ebx ; Src .text:00412DE6 push esi ; Dst .text:00412DE7 call _memcpy .text:00412DEC add esp, 0Ch .text:00412DEF dec ebp .text:00412DF0 sub edi, 3FFFFFFFh .text:00412DF6 sub ebx, 4 .text:00412DF9 sub esi, 4 .text:00412DFC .text:00412DFC loc_412DFC: ; CODE XREF: NewConnectionRequest+41j .text:00412DFC ; NewConnectionRequest+4Fj .text:00412DFC mov eax, ZonePlayerCount .text:00412E01 inc ebp .text:00412E02 add edi, 3FFFFFFFh .text:00412E08 add ebx, 4 .text:00412E0B add esi, 4 .text:00412E0E cmp ebp, eax .text:00412E10 jl loc_412D85 </code></pre> <p>As far as I understand it is that the <code>0x3FFFFFFF</code> has something to do with the bounds of the array?</p> <p>I think after the DisconnectUser and free of memory all the playerPointer pointers get shifted to the left is that correct? or it just changes the counter in different paths.</p> <p>I think the counter is either <code>v3</code> can keep increasing while the loop is going but when a player gets removed it starts checking from the end of the list or something?</p>
IDA PRO Hex-Rays 1.5 pseudo code understanding -=0x3FFFFFFFu; += 0x3FFFFFFFu;
|ida|decompilation|deobfuscation|hexrays|
<p>Your code snippet does not contain <code>push esp, ebp</code>, so why would there be an "old EBP" on the stack? At the beginning of the function, your stack should look like this:</p> <pre><code>esp + 00 | return address esp + 04 | Argument 1 (arg_0) esp + 08 | Argument 2 (arg_4) esp + 0C | Argument 3 (arg_8) </code></pre> <p>After that, remember that <code>esp</code> changes after each <code>push</code>. IDA is already doing the maths for you and splitting the displacement into the <code>+4</code> and <code>+arg_4</code> parts — they represent "balance <code>esp</code> back to its initial value" and "convert the remaining offset to a local variable", respectively. The function is pushing exactly those variables which are referenced:</p> <pre><code>push [esp+arg_8] ; Argument 3 push [esp+4+arg_4] ; Argument 2 push 15 push [esp+0Ch+arg_0] ; Argument 1 </code></pre> <hr> <p>If you want to find out more, you can highlight the <code>[esp+4+arg_4]</code> part in the disassembly and press <kbd>Q</kbd> to convert the displacement to a single number.</p> <p>Then go to Options > General... > Disassembly and enable the <code>Display disassembly line parts: [x] Stack pointer</code> setting. </p> <p>Now you see the difference between the <code>esp</code> value at the start of the function and the <code>esp</code> value in the current line.</p> <p>Subtract that difference from the displacement in the <code>push</code>, and you should get the right local variable.</p>
6273
2014-09-21T13:41:29.650
<p>i have the following function with three arguments:</p> <pre><code> sub_602667B proc near arg_0 = dword ptr 4 arg_4 = dword ptr 8 arg_8 = dword ptr 0Ch push [esp+arg_8] push [esp+4+arg_4] push 15 push [esp+0Ch+arg_0] </code></pre> <p>Then I make the following sketch : </p> <pre><code> esp, ebp -&gt; | Old EBP | +0 | Return Address | +4 | Argument 1 | +8 | Argument 2 | +12 | Argument 3 | +16 </code></pre> <p>And now I have the following on my paper:</p> <pre><code> push [esp+arg_8] =&gt; is Argument 2,( because esp + 12(=0Ch) = Argument 2 push [esp+4+arg_4] =&gt; is Argument 2,( because esp + 4 + 8 = Argument 2 ) push 15 push [esp+0Ch+arg_0] =&gt; is Argument 3,( because esp + 12 + 4 = 16 = Argument 3 </code></pre> <p>So my question would be : Is that sketch ok? I wanted to ask because the point that Argument 2 is pushed twice and Argument 1 is not taken surprises me </p>
Right order of function arguments
|assembly|stack|arguments|
<blockquote> <p>What's these instruction sequences for? </p> </blockquote> <p>They are for <strong>code optimization</strong>.</p> <h1>CPU cache</h1> <p>To optimize memory accesses, the CPU uses its own (small) internal memory called <em>cache</em>. It usually consists of several levels named <strong>L1</strong>, <strong>L2</strong> etc. A lower suffix number means that the memory is located <em>closer</em> to the CPU core, thus is <em>faster</em> to access, but it's <em>smaller</em> as well. An illustration of this concept taken from <a href="https://www.makeuseof.com/tag/what-is-cpu-cache/" rel="nofollow noreferrer">link</a> is given below:</p> <p><a href="https://i.stack.imgur.com/9Y8Bz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9Y8Bz.png" alt="CPU cache levels"></a></p> <p>Accessing the CPU cache is <em>critically faster</em> than reading RAM memory (see <a href="https://stackoverflow.com/questions/4087280/approximate-cost-to-access-various-caches-and-main-memory">this question</a> for more information) and that's why it is better to have data in cache instead of reading it each time from RAM (or even worse - hard disk).</p> <p>But the CPU doesn't cache only data - it caches <em>instructions</em> as well. And for instructions to be cached effectively, they have to be properly <em>aligned</em>. Following cite comes from <a href="https://www.agner.org/optimize/optimizing_assembly.pdf" rel="nofollow noreferrer">here</a>:</p> <blockquote> <p>Most microprocessors fetch code in aligned 16-byte or 32-byte blocks. If an important subroutine entry or jump label happens to be near the end of a 16-byte block then the microprocessor will only get a few useful bytes of code when fetching that block of code. It may have to fetch the next 16 bytes too before it can decode the first instructions after the label. </p> <p>This can be avoided by aligning important subroutine entries and loop entries by 16. [...] We may align subroutine entries by the cache line size (typically 64 bytes) if the subroutine is part of a critical hot spot and the preceding code is unlikely to be executed in the same context.</p> </blockquote> <p>So, it may be the case that under <code>foo1:</code> there is some short loop and compiler decided to align this block to put it in the CPU cache so it is executed faster.</p> <p>As @user45891 already stated in the comment, such an optimization in gcc is turned on with the option <code>-O2</code>, so don't use it when you don't want such optimizations.</p> <h1>But why the difference between the two outputs?</h1> <p>Because the first result comes from just two first states of compilation performed by gcc (<a href="https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html#Overall-Options" rel="nofollow noreferrer">link</a>):</p> <blockquote> <p>Compilation can involve up to four stages: preprocessing, compilation proper, assembly and linking, always in that order.</p> <p><code>-S</code></p> <p>Stop after the stage of compilation proper; do not assemble.</p> </blockquote> <p>While the second one is "entirely compiled" and linked.</p>
6278
2014-09-22T05:14:42.187
<p>Test is on x86 32bit Linux, Ubuntu 12.04, GCC 4.6.3 objdump 2.22</p> <p>Basically when I use <code>gcc</code> to produce assembly code of function <code>foo</code> like this:</p> <pre><code>gcc -S foo.c -O2 </code></pre> <p>At the end of function <code>foo</code>, I can get a sequence of instructions like this (I modified it and attached each instruction with its machine code to make it clear):</p> <pre><code> ...... 1977 .cfi_restore_state 1978 8B150000 0000 movl nodes, %edx 1979 89442410 movl %eax, 16(%esp) 1980 A1000000 00 movl i_depth, %eax 1981 8974240C movl %esi, 12(%esp) 1982 C7442404 FC000000 movl $.LC55, 4(%esp) 1983 89542414 movl %edx, 20(%esp) 1984 89442408 movl %eax, 8(%esp) 1985 C7042401 000000 movl $1, (%esp) 1986 E8FCFFFF FF call __printf_chk 1987 E937FFFF FF jmp .L181 1988 .L186: 1989 E8FCFFFF FF call __stack_chk_fail foo1: </code></pre> <p>Which looks normal.</p> <p>However, when I compiled + linked to create the ELF executable file, and then disassembly it with <code>objdump</code> like this:</p> <pre><code>gcc foo.c -O2 objdump -Dr -j .text foo </code></pre> <p>The instruction produced by disassembler looks like this (I modified a little bit to make it easier to understand):</p> <pre><code>11856 89442410 mov %eax,0x10(%esp) 11857 A1000000 00 mov 0x80851AC,%eax 11858 8974240C mov %esi,0xC(%esp) 11859 C7442404 00000000 movl $S_0x8064658,0x4(%esp) 11860 89542414 mov %edx,0x14(%esp) 11861 89442408 mov %eax,0x8(%esp) 11862 C7042401 000000 movl $0x1,(%esp) 11863 E8FCFFFF FF call __printf_chk 11864 E933FFFF FF jmp 0x80547EB 11865 11866 E8FCFFFF FF S_0x80548BC : call __stack_chk_fail 11867 EB0D jmp foo1 11868 90 nop 11869 90 nop 11870 90 nop 11871 90 nop 11872 90 nop 11873 90 nop 11874 90 nop 11875 90 nop 11876 90 nop 11877 90 nop 11878 90 nop 11879 90 nop 11880 90 nop 11881 foo1: </code></pre> <p>Looking at the end of function <code>foo</code>, I find out a sequence of instructions which can not be found in the original assembly code.</p> <p>It seems like a padding issue, but I am not sure.</p> <p>So my questions are:</p> <ol> <li>What's these instruction sequences for? </li> <li>Is there anyway to tell (assembler? linker?) do not generate these instruction sequences..? Because basically I am working a assembly code analysis tool, and these instruction sequences annoying the coding much.</li> </ol>
Weird instruction identified on disassembler produced assembly code
|disassembly|assembly|x86|objdump|
<p>BP on <code>CreateThread</code>, then see 3rd parameter -> <code>lpStartAddress</code> of the Thread (its EntryPoint). Now simply BP on that address and step from there when it breaks</p>
6279
2014-09-22T08:23:18.727
<p>I would like to step into some code which is ran on a new thread. Luckily, after the initial startup this is the only thread that is newly created in the program. I can set the debugger to break on the creation of a new thread. But all I see is the WinAPI and lower level calls that execute the thread. How can I step into the code that is executed on the thread to see what it does?</p>
Debugging the code executed on a new thread
|ollydbg|debugging|
<p>I found that (at least on Linux) it was reliable to intercept _init and to read from a constant offset from the stack pointer was pretty reliable. I ended up producing a pintool that would do just that. </p>
6280
2014-08-27T14:37:48.480
<p>I have a problem where I'm instrumenting stripped binaries; I don't know the start of <code>main()</code>. But there's always an <code>init()</code>, and <code>init()</code> calls <code>libc_start_main()</code>, which receives a pointer to main.</p> <p>If I can instrument libc with analysis code to intercept the argument, then I can retrieve that address and place another pin callback there so that I can get it's arguments. The problem is, I don't know what the calling convention is; I was thinking, if I could boil this down to a matter of the calling convention, then I do this for any function. I did notice that <code>gdb</code> knows the calling convention of <code>libc_start_main()</code>, in fact it is so good, it knows the order of the arguments as well.</p> <p>I did read a short note on stackoverflow that stated that the name of the function would yield the calling convention: « <a href="https://stackoverflow.com/questions/4162400/how-to-find-the-calling-convention-of-a-third-party-dll">How to find the calling convention of a third party dll?</a> »</p> <p>If it's not possible to know the calling convention programmatically, what is the opinion on creating a local build of libc in order to be able to force a particular calling convention onto <code>__libc_start_main()</code>... you see my chain of thought. Does anybody think that this is a better approach, rather than solving it in the general case ?</p>
How to programmatically identify binary calling convention?
|c++|calling-conventions|
<p>The most efficient and easiest way is to export the functionality using <code>dllexport</code> in C++.</p> <p>Any other way is rewriting the functionality of windows APIs which defeats point of writing an 'efficient' way to extend the functionality.</p> <p>You thought about doing what with <code>LoadLibrary</code>? You know that <code>LoadLibrary</code> returns the base address of where it's loaded? Or you could even use <code>GetModuleHandle</code> to get the base. So, it's easy enough to do <code>Base + Offset</code></p> <p>If this doesn't answer your question then you can elaborate why you can't use <code>dllexport</code>?</p> <p>Edit: Inside your dll add the code:</p> <pre><code>__declspec(dllexport) void __stdcall ShowMessageBox( ) { MessageBoxA( 0, "HelloWorld from exported function!", "", MB_OK ); } </code></pre> <p>Inside your exe add the code:</p> <pre><code>#pragma comment(lib, "TheFullPathToYourOutputDirOrUseRelaltive\\Bla.lib") __declspec(dllimport) void __stdcall ShowMessageBox( ); </code></pre> <p>The lib file will be generated in the output directory of your dll. This is only required for build and isn't required for distribution to your end-users.</p> <p>Finally call our function <code>ShowMessageBox( );</code>. </p>
6283
2014-09-22T20:13:16.543
<p>I have wrote a program in C++ and I built it as a DLL. I want to utilize functions that are in this DLL in another program to overwrite other functions. Unfortunately, they're not any exports and cannot be added to the imports table. Not only that I have functions that I would like to be able to <code>jmp</code> to and utilize and then return. </p> <p>Did I perhaps build this incorrectly ?</p> <p>I have the source so I can make changes in VSC++ although, I can would preferable like to do this in ASM.</p> <p>I have thought about calling <code>LoadLibrary()</code> but that I believe will put the DLL in a random location and making patches to this will be a bit difficult, if I am not mistaken.</p> <p>Let me know your ideas on how I can solve this.</p>
Most efficient way to extend a program using a DLL
|disassembly|ollydbg|x86|dll|
<p>As Igor stated, the <code>.ctors</code> section is a list of function pointers, ending with a sentinel value of <code>0xffffffff</code>. To see its contents, just do</p> <pre><code>$ objdump -s -j.ctors bar.so </code></pre> <p>But your assembly file only contains weak symbols. Those are foreign functions in other libraries, and are invoked when their libraries are loaded at runtime.</p> <p>For example, put this in a file <code>bar.cpp</code>:</p> <pre><code>class Foo { public: int i; Foo(int n) : i(n) { } }; Foo global_foo(123); </code></pre> <p>Compile with</p> <pre><code>$ g++ -shared -fPIC bar.cpp -obar.so </code></pre> <p>The contents of the <code>.init_array</code> section is</p> <pre><code>$ objdump -s -j.init_array bar.so bar.so: file format elf64-x86-64 Contents of section .init_array: 200820 ad060000 00000000 ........ </code></pre> <p>There's a function pointer there, <code>0xad060000 00000000</code>. But you have to change its endianness, e.g. with Python:</p> <pre><code>&gt;&gt;&gt; import struct &gt;&gt;&gt; import binascii &gt;&gt;&gt; binascii.hexlify(struct.pack("&lt;Q", 0xad06000000000000)) '00000000000006ad' </code></pre> <p>Now list all symbols and grep for that address:</p> <pre><code>$ objdump -C --syms bar.so | grep 00000000000006ad 00000000000006ad l F .text 0000000000000015 [... on above line ...] global constructors keyed to bar.cpp </code></pre> <p>The disassembly for it,</p> <pre><code>$ objdump -C -d bar.so </code></pre> <p>shows</p> <pre><code>00000000000006ad &lt;global constructors keyed to bar.cpp&gt;: 6ad: 55 push %rbp 6ae: 48 89 e5 mov %rsp,%rbp 6b1: be ff ff 00 00 mov $0xffff,%esi 6b6: bf 01 00 00 00 mov $0x1,%edi 6bb: e8 ba ff ff ff callq 67a &lt;__static_initialization_and_destruction_0(int, int)&gt; 6c0: c9 leaveq 6c1: c3 retq </code></pre> <p>which jumps to <code>__static_initialization_and_destruction_0(int, int)</code>:</p> <pre><code>000000000000067a &lt;__static_initialization_and_destruction_0(int, int)&gt;: 67a: 55 push %rbp 67b: 48 89 e5 mov %rsp,%rbp 67e: 48 83 ec 10 sub $0x10,%rsp 682: 89 7d fc mov %edi,-0x4(%rbp) 685: 89 75 f8 mov %esi,-0x8(%rbp) 688: 83 7d fc 01 cmpl $0x1,-0x4(%rbp) 68c: 75 1d jne 6ab &lt;__static_initialization_and_destruction_0(int, int)+0x31&gt; 68e: 81 7d f8 ff ff 00 00 cmpl $0xffff,-0x8(%rbp) 695: 75 14 jne 6ab &lt;__static_initialization_and_destruction_0(int, int)+0x31&gt; 697: be 7b 00 00 00 mov $0x7b,%esi 69c: 48 8b 05 9d 03 20 00 mov 0x20039d(%rip),%rax # 200a40 &lt;_DYNAMIC+0x1e8&gt; 6a3: 48 89 c7 mov %rax,%rdi 6a6: e8 f5 fe ff ff callq 5a0 &lt;Foo::Foo(int)@plt&gt; 6ab: c9 leaveq 6ac: c3 retq </code></pre> <p>which puts 123 (<code>0x7b</code>) on the stack and calls <code>Foo::Foo(int)</code>.</p>
6285
2014-09-23T00:54:35.983
<p>Test is on x86, 32-bit Linux. I am using <code>g++</code> 4.6.3 and <code>objdump</code> 2.22</p> <p>Here is a simple C++ code I am working on:</p> <pre><code>#include &lt;iostream&gt; using namespace std; main() { cout &lt;&lt; &quot;Hello World!&quot; &lt;&lt; endl; return 0; } </code></pre> <p>When I compile it into assembly code using :</p> <pre><code>gcc -S hello.cc </code></pre> <p>I can find out a <code>ctors</code> section in the <strong>hello.s</strong> below:</p> <pre><code>.section .ctors,&quot;aw&quot;,@progbits .align 4 .long _GLOBAL__sub_I_main .weakref _ZL20__gthrw_pthread_oncePiPFvvE,pthread_once .weakref _ZL27__gthrw_pthread_getspecificj,pthread_getspecific .weakref _ZL27__gthrw_pthread_setspecificjPKv,pthread_setspecific .weakref _ZL22__gthrw_pthread_createPmPK14pthread_attr_tPFPvS3_ES3_,pthread_create .weakref _ZL20__gthrw_pthread_joinmPPv,pthread_join .weakref _ZL21__gthrw_pthread_equalmm,pthread_equal .weakref _ZL20__gthrw_pthread_selfv,pthread_self .weakref _ZL22__gthrw_pthread_detachm,pthread_detach .weakref _ZL22__gthrw_pthread_cancelm,pthread_cancel .weakref _ZL19__gthrw_sched_yieldv,sched_yield .weakref _ZL26__gthrw_pthread_mutex_lockP15pthread_mutex_t,pthread_mutex_lock .weakref _ZL29__gthrw_pthread_mutex_trylockP15pthread_mutex_t,pthread_mutex_trylock .weakref _ZL31__gthrw_pthread_mutex_timedlockP15pthread_mutex_tPK8timespec,pthread_mutex_timedlock .weakref _ZL28__gthrw_pthread_mutex_unlockP15pthread_mutex_t,pthread_mutex_unlock .weakref _ZL26__gthrw_pthread_mutex_initP15pthread_mutex_tPK19pthread_mutexattr_t,pthread_mutex_init .weakref _ZL29__gthrw_pthread_mutex_destroyP15pthread_mutex_t,pthread_mutex_destroy .weakref _ZL30__gthrw_pthread_cond_broadcastP14pthread_cond_t,pthread_cond_broadcast .weakref _ZL27__gthrw_pthread_cond_signalP14pthread_cond_t,pthread_cond_signal .weakref _ZL25__gthrw_pthread_cond_waitP14pthread_cond_tP15pthread_mutex_t,pthread_cond_wait .weakref _ZL30__gthrw_pthread_cond_timedwaitP14pthread_cond_tP15pthread_mutex_tPK8timespec,pthread_cond_timedwait .weakref _ZL28__gthrw_pthread_cond_destroyP14pthread_cond_t,pthread_cond_destroy .weakref _ZL26__gthrw_pthread_key_createPjPFvPvE,pthread_key_create .weakref _ZL26__gthrw_pthread_key_deletej,pthread_key_delete .weakref _ZL30__gthrw_pthread_mutexattr_initP19pthread_mutexattr_t,pthread_mutexattr_init .weakref _ZL33__gthrw_pthread_mutexattr_settypeP19pthread_mutexattr_ti,pthread_mutexattr_settype .weakref _ZL33__gthrw_pthread_mutexattr_destroyP19pthread_mutexattr_t,pthread_mutexattr_destroy </code></pre> <p>However, when I assembly the asm code, producing an exe file and use the <code>objdump</code> produce the <code>ctors</code> section's contain like this:</p> <pre><code>objdump -Dr -j .ctors hellocpp </code></pre> <p>All I can get is like this:</p> <pre><code>hellocpp: file format elf32-i386 Disassembly of section .ctors: 08049efc &lt;__CTOR_LIST__&gt;: 8049efc: ff (bad) 8049efd: ff (bad) 8049efe: ff (bad) 8049eff: ff 00 incl (%eax) 08049f00 &lt;__CTOR_END__&gt;: 8049f00: 00 00 add %al,(%eax) ... </code></pre> <p>Currently I am trying to recover the content of some ELF binaries compiled from <code>c++</code> program..</p> <p>So I am wondering if there is a way to get the content of <code>ctors</code> which equals to what <code>g++</code> produced?</p> <h3>Update:</h3> <p>Thanks a lot for @Igor's help. But I am still trapped in looking for <code>class's</code> <code>constructor</code> and <code>destructor</code> info from ELF binary.</p> <p>When evolving <code>class</code> definition, g++ would produce these info in the <code>.ctors</code> section:</p> <pre><code> .globl _ZN8ComputerC1Ev .set _ZN8ComputerC1Ev,_ZN8ComputerC2Ev .globl _ZN8ComputerD1Ev .set _ZN8ComputerD1Ev,_ZN8ComputerD2Ev </code></pre> <p>Generally <code>_ZN8ComputerC2Ev</code> is the name of a class's constructor while <code>_ZN8ComputerD2Ev</code> is its destructor.</p> <p>However, I just can not find corresponding info in the <code>objdump</code> dumped <code>.ctors</code> or <code>.init_array</code> sections.. I also tried <code>.eh_frame</code> and <code>gcc_except_table</code>, but the information dumped is massive.. I can not figure out the meaning of those information..</p> <p>Could anyone give me guide?</p>
How to recover information stored in .ctors section?
|disassembly|x86|c++|elf|
<p>The bytes at offset 0x10 are <code>78 DA</code>, which hints very strongly to the zlib compression algorithm. </p> <pre><code>0000000000: 00 52 42 42 00 6C 8C 60 │ 00 3E CE 22 27 4A 88 69 RBB lŒ` &gt;Î"'Jˆi 0000000010: 78 DA 74 9D 0B BC 97 63 │ D6 F7 77 24 A9 B0 25 95 xÚt♂¼—cÖ÷w$©°%• ^^^^^ </code></pre> <p>I use this small Python script to decompress zlib-compressed streams:</p> <pre><code># usage: unz.py infile outfile [start offset] import zlib, sys inf = open(sys.argv[1],"rb") off = 0 if len(sys.argv)&gt;3: off = int(sys.argv[3],16) inf.seek(off) cdata = inf.read() # auto-detect zlib/gzip/deflate # http://stackoverflow.com/a/22310760/422797 d = zlib.decompressobj(zlib.MAX_WBITS|32) udata = d.decompress(cdata) udata += d.flush() clen = len(cdata) - len(d.unused_data) ulen = len(udata) open(sys.argv[2],"wb").write(udata) print("%d -&gt; %d; end of data: %08X" % (clen, ulen, off+clen)) </code></pre> <p>If I use it like this:</p> <pre><code>unz.py CITY.RBB CITY.UNP 10 </code></pre> <p>It decompresses nicely:</p> <pre><code>3696259 -&gt; 7113808; end of data: 00386693 </code></pre> <p>And the output has some structure:</p> <pre><code>0000000000: 00 00 00 01 00 00 00 00 │ 00 00 00 01 00 00 00 01 ☺ ☺ ☺ 0000000010: 00 00 00 01 02 00 00 02 │ 00 00 00 50 00 6C 8C 10 ☺☻ ☻ P lŒ► 0000000020: 00 00 00 10 00 00 00 01 │ 00 00 00 00 00 00 00 00 ► ☺ 0000000030: CA 60 FA A2 42 43 52 00 │ 00 00 00 00 00 00 00 61 Ê`ú¢BCR a 0000000040: 58 58 58 58 58 58 58 58 │ 58 58 58 58 58 58 58 58 XXXXXXXXXXXXXXXX 0000000050: 00 00 00 00 00 0D C4 6C │ 00 55 35 E0 00 61 3E 30 ♪Äl U5à a&gt;0 0000000060: 00 63 79 F0 00 01 30 D3 │ 00 00 43 C7 00 03 02 14 cyð ☺0Ó CÇ ♥☻¶ 0000000070: 00 00 8E F0 00 00 C1 7E │ 00 00 00 00 00 00 00 00 Žð Á~ 0000000080: 00 61 3E 30 FF FF FF FF │ C3 7C D3 18 C2 B4 AF 10 a&gt;0ÿÿÿÿÃ|Ó↑´¯► 0000000090: C4 74 57 67 C4 FB 0A 00 │ C4 A2 0D 4B C4 F5 E2 F3 ÄtWgÄû◙ Ä¢♪KÄõâó 00000000A0: 44 BB D5 3A 44 8B 77 68 │ 41 45 C6 00 00 00 00 00 D»Õ:D‹whAEÆ </code></pre> <p>However, making sense of it may require you to look at the game code.</p>
6297
2014-09-24T06:03:09.953
<p>I'm trying to figure out how this .RBB file is packed it's from a gamecube game I'm trying to learn how to reverse engineer it so I can extract the file and look at its contents. </p> <p>I don't know were to start honestly so I was hoping someone could point me in the right direction. I've added a link to the file below incase anyone wants to take a look at it.</p> <p><a href="https://dl.dropboxusercontent.com/u/227520696/CITY.RBB" rel="nofollow noreferrer">https://dl.dropboxusercontent.com/u/227520696/CITY.RBB</a></p> <p>Additional Information:</p> <p>The game is called Extreme G Racing</p> <p>Edit: I've looked it with a hex editor and it shows some japanese text</p> <p><img src="https://i.stack.imgur.com/Ekv3V.png" alt="enter image description here"></p>
Help old gamecube file format
|memory|decompress|
<p><a href="http://web.archive.org/web/20071020232030/http://www.alex-ionescu.com/vb.pdf" rel="nofollow">http://web.archive.org/web/20071020232030/http://www.alex-ionescu.com/vb.pdf</a></p> <p>[more chars ftw][more chars ftw]</p>
6306
2014-09-24T17:45:14.177
<p>Where i can find a working link to this tutorial? I have searched a lot on the net but all links are broken. Could anyone upload it somewhere?</p> <p>Original link <a href="http://www.alex-ionescu.com/vb.pdf" rel="nofollow">http://www.alex-ionescu.com/vb.pdf</a></p>
Where can i find Visual Basic Image Internal Structure Format by Alex Ionescu?
|patch-reversing|visual-basic|
<p>(I think you may get some extra comments if you use <code>-fverbose-asm</code>.)</p> <p>Recovering information from these tables is definitely possible, although documentation is scarce and is often present only in the code which parses them. </p> <p>The <code>.eh_frame</code> layout is described briefly in the <a href="http://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html">LSB documentation</a>. Ian Lance Taylor (author of the gold linker) also made some blog posts on <a href="http://www.airs.com/blog/archives/460"><code>.eh_frame</code></a> and <a href="http://www.airs.com/blog/archives/464"><code>.gcc_except_table</code> layout</a>.</p> <p>For a more reference-like description, check my <a href="http://www.hexblog.com/wp-content/uploads/2012/06/Recon-2012-Skochinsky-Compiler-Internals.pdf">Recon 2012 slides</a> (start at 37 or so).</p> <p>I've made <a href="http://www.hexblog.com/wp-content/uploads/2012/06/recon-2012-skochinsky-scripts.zip">an IDA script</a> (<code>gcc_extab.py</code>) which parses <code>.eh_frame</code> and <code>.gcc_except_table</code> and formats them nicely.</p> <p>Taking a sample program:</p> <pre><code>void f() { throw 1; } int main() { int j; try { f(); } catch (int i) { j = i; } return 0; } </code></pre> <p>I'll show the commented structures produced by GCC.</p> <p>First, the <code>.eh_table</code> (some parts omitted for clarity):</p> <pre><code>.Lframe1: # start of CFI 1 .long .LECIE1-.LSCIE1 # length of CIE 1 data .LSCIE1: # start of CIE 1 data .long 0 # CIE id .byte 0x1 # Version .string "zPL" # augmentation string: # z: has augmentation data # P: has personality routine pointer # L: has LSDA pointer .uleb128 0x1 # code alignment factor .sleb128 -4 # data alignment factor .byte 0x8 # return address register no. .uleb128 0x6 # augmentation data length (z) .byte 0 # personality routine pointer encoding (P): DW_EH_PE_ptr|DW_EH_PE_absptr .long __gxx_personality_v0 # personality routine pointer (P) .byte 0 # LSDA pointer encoding: DW_EH_PE_ptr|DW_EH_PE_absptr .byte 0xc # Initial CFI Instructions [...] .align 4 .LECIE1: # end of CIE 1 [...] .LSFDE3: # start of FDE 3 .long .LEFDE3-.LASFDE3 # length of FDE 3 .LASFDE3: # start of FDE 3 data .long .LASFDE3-.Lframe1 # Distance to parent CIE from here .long .LFB1 # initial location .long .LFE1-.LFB1 # range length .uleb128 0x4 # Augmentation data length (z) .long .LLSDA1 # LSDA pointer (L) .byte 0x4 # CFI instructions .long .LCFI2-.LFB1 [...] .align 4 .LEFDE3: # end of FDE 3 </code></pre> <p>Next, the LSDA (language-specific data area) in <code>.gcc_except_table</code>, referenced by FDE 3:</p> <pre><code>.LLSDA1: # LSDA 1 .byte 0xff # LPStart encoding: DW_EH_PE_omit .byte 0 # TType encoding: DW_EH_PE_ptr|DW_EH_PE_absptr .uleb128 .LLSDATT1-.LLSDATTD1 # TType offset .LLSDATTD1: # LSDA 1 action table .byte 0x1 # call site encoding: DW_EH_PE_uleb128|DW_EH_PE_absptr .uleb128 .LLSDACSE1-.LLSDACSB1 # call site table length .LLSDACSB1: # LSDA 1 call site entries .uleb128 .LEHB0-.LFB1 # call site 0 start .uleb128 .LEHE0-.LEHB0 # call site 0 length .uleb128 .L8-.LFB1 # call site 0 landing pad .uleb128 0x1 # call site 0 action (1=action 1) .uleb128 .LEHB1-.LFB1 # call site 1 start .uleb128 .LEHE1-.LEHB1 # call site 1 length .uleb128 0 # call site 1 landing pad .uleb128 0 # call site 1 action (0=no action) .LLSDACSE1: # LSDA 1 action table entries .byte 0x1 # action 1 filter (1=T1 typeinfo) .byte 0 # displacement to next action (0=end of chain) .align 4 .long _ZTIi # T1 typeinfo ("typeinfo for int") .LLSDATT1: # LSDA 1 TTBase </code></pre>
6311
2014-09-25T01:01:21.850
<p>For <code>C++</code> program with <code>try</code> <code>catch</code> defined, when using <code>g++</code> to compile it into assembly code (test is on x86 32bit Linux, <code>g++</code> 4.6.3)</p> <pre><code>g++ -S cppexcept.cc </code></pre> <p>A specified section called <code>.gcc_except_table</code> is produced like below:</p> <pre><code> .section .gcc_except_table .align 4 .LLSDA980: .byte 0xff .byte 0 .uleb128 .LLSDATT980-.LLSDATTD980 .LLSDATTD980: .byte 0x1 .uleb128 .LLSDACSE980-.LLSDACSB980 .LLSDACSB980: .uleb128 .LEHB3-.LFB980 .uleb128 .LEHE3-.LEHB3 .uleb128 0 .uleb128 0 .uleb128 .LEHB4-.LFB980 .uleb128 .LEHE4-.LEHB4 .uleb128 .L19-.LFB980 .uleb128 0x3 .uleb128 .LEHB5-.LFB980 .uleb128 .LEHE5-.LEHB5 .uleb128 0 .uleb128 0 .uleb128 .LEHB6-.LFB980 .uleb128 .LEHE6-.LEHB6 .uleb128 .L20-.LFB980 .uleb128 0 .uleb128 .LEHB7-.LFB980 .uleb128 .LEHE7-.LEHB7 .uleb128 .L21-.LFB980 .uleb128 0 </code></pre> <p>After the compilation into <code>exe file</code> with <code>ELF</code> format, it seems that there are two sections related to exception handling, which are <code>.gcc_except_table</code> and <code>.eh_frame</code>. </p> <p>However, I dumped the contents of these two section with the following commands, comparing the labels' memory addresses with what are defined in <code>.gcc_except_table</code>, but it seems too blur to me...</p> <pre><code>objdump -s -j .gcc_except_table cppexcept objdump -s -j .eh_frame cppexcept </code></pre> <p>So my question is:</p> <p>Is there any way to recover the information defined in the <code>.gcc_except_table</code> (which is shown above) from <code>ELF</code> file's <code>.gcc_except_table</code> and <code>eh_frame</code> tables?</p>
How to recover the exception info from .gcc_except_table and .eh_handle sections?
|disassembly|assembly|x86|c++|exception|
<blockquote> <p>What are the publicly available exploits for Java that one can study ?</p> </blockquote> <p>There are about 20 publicly available exploits for Java here, with annotated source code and references to the vulnerabilities being exploited: <a href="https://github.com/rapid7/metasploit-framework/tree/master/modules/exploits/multi/browser" rel="nofollow">https://github.com/rapid7/metasploit-framework/tree/master/modules/exploits/multi/browser</a></p>
6314
2014-09-25T13:49:23.777
<p>I am looking to get started with Java exploitation. I have not found a good place start or even how to start, so I am asking here. What are the publicly available exploits for Java that one can study ? Also what would be a good starting point ?(ex. maybe decompilation ) </p>
exploit - Getting started with Java exploitation
|exploit|java|
<p>The problem is that there is no notion of inner classes at the bytecode level. Each inner class is compiled to a separate class with no special privileges compared to any other class in the same package.</p> <p>So in order to support the functionality of inner classes, the compiler has to add getter methods behind the scenes. Every time you access a field in the outer class from the inner class, the compiler needs to generate a getter in the outer class. However, these getters cannot be private because then nothing could call them! Therefore, the getter is always at least protected, meaning any class in the same package can access it.</p> <p>Update: <a href="https://openjdk.java.net/jeps/181" rel="nofollow noreferrer">Java 11 added a new bytecode feature to address this issue</a>, so this does not apply to recent versions of Java.</p>
6320
2014-09-26T14:51:03.367
<p>I recently heard that using Java inner classes in a class that enclose sensitive information is causing the <code>private</code> data of the class to be changed to <code>protected</code> at the bytecode level (meaning that any other class of the package may access it).</p> <p>As I do not have any expertise in bytecode reading I would like to know if it is true, and get some explanation of this problem.</p>
What is the problem with using inner classes in a class enclosing sensitive information?
|exploit|java|
<p>Mostly cleaned up, you can rename vars if you will. <a href="http://pastebin.com/uySNcxuX" rel="nofollow">pastebin</a></p>
6327
2014-09-27T15:21:02.240
<p>Can someone deobfuscate this code? I am not getting any way to deobfuscate this.</p> <p>Unable to paste it over here as it over passed 30,000 word limit.</p> <p><a href="http://pastebin.com/V327Q8Hg" rel="nofollow">http://pastebin.com/V327Q8Hg</a></p> <p>Thanks</p>
Trying to deobfuscate multi layered javascript
|obfuscation|deobfuscation|javascript|
<p>You can also give a try to <a href="https://software.intel.com/sites/landingpage/pintool" rel="nofollow">pin</a>. There is even an <a href="https://software.intel.com/sites/landingpage/pintool/docs/49306/Pin/html/index.html#SimpleCount" rel="nofollow">example</a> in the documentation explaining exactly what you want to do.</p>
6329
2014-09-27T16:27:25.803
<p>How can I measure the number of instructions a Windows (or Linux or XNU) kernel driver/module executed after, say, an IOCTL or a SYSCALL? My only ideas are the following:</p> <ul> <li>Using WinDBG or remote GDB, debug the whole operating system, put breakpoints in each basic block/function/instruction of the driver or step-trace inside it. Very slow and likely going to cause problems due to the large number of breakpoints to be added.</li> <li>From user-land, use instructions like RDTSC to try to "measure" the number of (non different) instructions executed by checking the times it took to execute it. Likely going to give "false" results for many reasons (i.e., the very same call to a syscall or ioctl can take different times for many different reasons).</li> </ul> <p>Any idea or option in any of the mentioned kernels to determine the number of instructions and, preferably, the number of <em>different</em> instructions executed?</p>
Determining the number of instructions executed by a driver
|kernel-mode|instrumentation|
<p>Well, so, you can use <a href="http://jsbeautifier.org/" rel="nofollow">http://jsbeautifier.org/</a> with unescape printable chars to get the top var decoded, then, if you look closely, you should see that the values of the var are used everywhere with an index, so you can just write a quick script to replace it with the actual value. End result is <a href="http://pastebin.com/iJqs6Jq3" rel="nofollow">here</a></p> <p>Python to replace the var:</p> <pre><code>#Replace.py //probably not optimized, so dont be too harsh on me _0x4b6a=[copy-pasteValueDecodedFromScript] with open('EncodedScript.js') as fp: for line in fp: for i in range(0,608): line = line.replace("_0x4b6a["+str(i)+"]", _0x4b6a[i]) print line </code></pre>
6334
2014-09-28T20:19:37.577
<p>I am having a obfuscated JS file and I want to deobfuscate it (and <em>not beautify it</em>). I have seen answer to a <a href="https://reverseengineering.stackexchange.com/questions/1436/analyzing-highly-obfuscated-javascript">similar question here</a> and I tried de-obfuscating a the file using online version of JSUnpack and JSDetox. However, I am still not able to deobfuscate it. The JS file is not a malware but it is used to inject ads into web-page. So, any analyser analysing the file won't find anything malicious. The problem is that the JS stores (hex) strings in string array and using it to concatenate the code. JSDetox atleast decodes the string array in the beginning of the file. However, the readability is not improved anyway as the whole code makes use of the string array. If anyone wants to take a look at the file they can find it <a href="http://pastebin.com/vYSVe4KX" rel="nofollow noreferrer">here</a>.</p> <p>Any kind of help would be appreciated! Thanks.</p> <p><strong>Edit:</strong> I have also tried Malzilla now because I found a similar technique <a href="https://reverseengineering.stackexchange.com/questions/2103/try-to-deobfuscate-multi-layered-javascript?rq=1">here</a>. However, the script probably has some errors which is tolerated by Chrome. However, when I click "Run Script" in Malzilla, I get a message saying "Script cannot be compiled". I tried to debug script using the "Debug Script" button, the window highlights some line saying "InterYeildOptions is not defined" and I don't know what to do about it. :-/</p>
Deobfuscating a javascript file
|deobfuscation|javascript|
<p>I don't think that this is possible now; feel free to open an issue on Hopper's <a href="http://www.hopperapp.com/bugtracker/" rel="nofollow">bugtracker</a>.</p>
6338
2014-09-29T11:40:55.903
<p>Hopper allows you to change the representation of numbers in the disassembly window so that:</p> <pre><code>0000be84 str r3, [r11, #0xfffffff0] </code></pre> <p>becomes:</p> <pre><code>0000be84 str r3, [r11, #-0x10] </code></pre> <p>This doesn't carry over into the decompiled code though:</p> <pre><code>r3 = *(r11 + 0xffffffffffffffd8); </code></pre> <p>Whilst it's not a major thing, it would be nice for the representation to be carried across.</p> <p>Can this be done?</p>
Signed/unsigned representation of ints in decompiled code in Hopper
|decompilation|hopper|
<p>I've managed to create a php script that does the CRC calculation by debugging the application using OllyDbg.</p> <p>The CRC is calculated by Adding up every 2 bytes (every short). if the result is larger than a short, the 'most significant short' is added to the 'least significant short' until the result fits in a short. Finally, the CRC (short) is inverted.</p> <p>I'll add my php script for completeness:</p> <pre><code>&lt;?php function CompareHash($telegram) { $telegram = str_replace(" ", "", $telegram); $telegram_crc = substr($telegram, 4, 4); $telegram = str_replace($telegram_crc, "0000", $telegram); echo "Telegram: ", $telegram, ', Crc: ', $telegram_crc, ' (', hexdec($telegram_crc), ')&lt;br /&gt;'; $crc = 0; $i = 0; while ($i &lt; strlen($telegram)) { $short = substr($telegram, $i, 4); if (strlen($short) &lt; 4) $short = $short . '00'; $crc += hexdec($short); $i += 4; } echo "Crc: ", $crc, ', inverse: ', ~$crc; // Region "truncate CRC to Int16" while($crc &gt; hexdec('FFFF')) { $short = $crc &amp; hexdec ('FFFF'); // Region "unsigned shift right by 16 bits" $crc = $crc &gt;&gt; 16; $crc = $crc &amp; hexdec ('FFFF'); // End region $crc = $short + $crc; } // End region // Region "invert Int16" $crc = ~$crc; $crc = $crc &amp; hexdec ('FFFF'); // End region echo ', shifted ', $crc; if (hexdec($telegram_crc) == $crc) { echo "&lt;br /&gt;MATCH!!! &lt;br /&gt;"; } else { echo "&lt;br /&gt;failed .... &lt;br /&gt;"; } } $s1_full = "E8 03 17 FC 00 00 00 00"; $s2_full = "D0 07 71 BC BE 3B 00 00"; $s3_full = "D0 07 4E D4 E1 23 00 00"; $s4_full = "D0 07 35 32 BE 3B 07 00 7E 44 65 76 69 63 65 4E 61 6D 65 3D 54 41 38 31 30 00"; $s5_full = "0B 00 39 6C BE 3B 05 00 7E 52 46 43 61 72 64 4F 6E"; CompareHash($s1_full); CompareHash($s2_full); CompareHash($s3_full); CompareHash($s4_full); CompareHash($s5_full); ?&gt; </code></pre> <p>Thanks for the feedback!</p>
6342
2014-09-29T12:35:24.643
<blockquote> <p>(i've also posted this question on stackoverflow before i found out there was a specific stackexchange site for reverse engineering. My bad. Original post here: <a href="https://stackoverflow.com/questions/26095009/need-help-reverse-engineering-a-crc16">https://stackoverflow.com/questions/26095009/need-help-reverse-engineering-a-crc16</a>)</p> </blockquote> <p>I'm trying to connect to the Safecom TA-810 (badge/registration system) to automate the process of calculating how long employee's have worked each day. Currently this is done by:</p> <ol> <li>Pulling the data into the official application</li> <li>Printing a list of all 'registrations'</li> <li>Manually entering the values from the printed lists into our HR application</li> </ol> <p>This is a job that can take multiple hours which we'd like to see automated. So far the official tech support has been disappointing and refused to share any details.</p> <p>Using wireshark I have been capturing the UDP transmissions and have pretty much succeeded in understanding how the protocol is built up. I'm only having issues with what i suppose is a CRC field. I don't know how it is calculated (CRC type and parameters) and using which fields ...</p> <p>This is how a message header looks like:</p> <pre><code>D0 07 71 BC BE 3B 00 00 D0 07 - Message type 71 BC - This i believe is the CRC BE 3B - Some kind of session identifier. Stays the same for every message after the initial message (initial message has '00 00' as value) 00 00 - Message number. '01 00', '02 00', '03 00' </code></pre> <p>Some examples:</p> <pre><code>Header only examples E8 03 17 FC 00 00 00 00 -&gt; initial request (#0, no session nr) D0 07 71 BC BE 3B 00 00 -&gt; Initial response (#0, device sends a session nr) 4C 04 EF BF BE 3B 06 00 -&gt; Message #6, still using the same session # as the initial response Larger example, which has data 0B 00 07 E1 BE 3B 01 00 7E 45 78 74 65 6E 64 46 6D 74 </code></pre> <p>I've also been trying to figure this out by reading the disassembled code from the original application. The screenshot below happens before the socket.sendto and seems to be related.</p> <p><img src="https://i.stack.imgur.com/Q8cqg.png" alt="original application code"></p> <p>Any help will be extremely appreciated.</p> <p><strong>EDIT</strong>: Made some success with debugging the application using ollydbg. The CRC appears in register (reversed) EDX at the selected line in the following screenshot.</p> <p><img src="https://i.stack.imgur.com/u0mTF.png" alt="crc showing up"></p>
Safecom TA-810 protocol (having trouble with the CRC)
|ollydbg|protocol|
<p>Because the code at 0x4164e3 is never referenced in a CALL or JMP instruction, but (probably) used as data somewhere else (as you said the program is self-modifying), Olly thinks it's data, and has no reason to assume there's code there. See <a href="https://stackoverflow.com/questions/13812554/in-ollydbg-how-do-you-force-hint-disassembly-at-a-location">https://stackoverflow.com/questions/13812554/in-ollydbg-how-do-you-force-hint-disassembly-at-a-location</a> for how to make sure olly treats that address as code.</p> <p>(In case the link goes away: Right Click -> Analysis -> During Next analysis, treat selection as -> Command, Or at least "remove analysis from section" to tell olly NOT to assume data.)</p> <p>The problem with single-stepping exception handlers is: If you do any kind of single-stepping, the debugger will place a breakpoint at the next instruction, execute the code at the current instruction, and hope for the breakpoint to return control to the debugger. However, the exception will call the exception handler, but the debugger doesn't even know the instruction is going to raise an exception, so it can't put the breakpoint at the exception handler's address. So, your single-step executes the exception handler (without returning to the debugger), which probably checks for the breakpoint after the instruction it came from (to actively detect a debugger) and, if it detects a debugger, jumps to "nowhere" to make the program crash/confuse the debugger user.</p> <p>There are lots of explanations on the internet that are more thorough than what i could write in a short answer, googling for "exception handler single step" brings up a few nice examples.</p>
6354
2014-10-01T12:54:21.337
<p>I'm not sure if there are any legal hinderances to me asking this question, so if asking for unpacking advice is against the rules I apologize.</p> <p>I am new to reverse engineering and trying to manually unpack a PEtite 2.2/2.3 as a learning experience and have been trying to follow this guide: <a href="http://users.freenet.am/~softland/tutorials/Petite.v2.3.MUP.txt" rel="nofollow noreferrer">http://users.freenet.am/~softland/tutorials/Petite.v2.3.MUP.txt</a>. The program I'm unpacking is the original PEtite packer itself.</p> <p>I have disabled passing on exceptions as it feels like cheating and I haven't fully grasped how exceptions work in this context, seemingly used here to derail the debugger, so I'd like to know why and how to work around it myself. I've come to this part in the guide:</p> <pre><code>and this exception program generates for jumping to exception handler, so at that line put breakpoint on exception handler (goto to 4164E3 and press F2), then press SHIFT+F9 and you are at the beginning of exception handle </code></pre> <p>When using OllyDbg 1.10 (non-patched), this is what I find at the address of the exception handler (this address is also where Olly said the OEP would be when I tried out the auto-unpacker SFX ability):</p> <p><img src="https://i.stack.imgur.com/V6AAr.png" alt="enter image description here"></p> <p>In the guide it says that I should find the line <code>004164E3 CALL PETGUI.00416537</code> here. As you can see there is really nothing here, however it was the address I always ended up at no matter the method I tried to use (or saw in tutorials etc.), so I did a process dump and suddenly I got this:</p> <p><img src="https://i.stack.imgur.com/zAa8k.png" alt="enter image description here"></p> <p>Now it struck me that since the program is self-modifying that might naturally confuse Olly, so I told Olly to re-analyze the code (before dumping the process), and I ended up with this:</p> <p><img src="https://i.stack.imgur.com/AcIbr.png" alt="enter image description here"></p> <p>I got the expected result, but there's something missing... the <code>CALL</code> instruction can be seen in the opcode section but it hasn't been parsed by Olly. Now to my questions:</p> <ol> <li>Why doesn't Olly parse this <code>CALL</code> instruction properly?</li> <li>How come <code>E8 4F000000</code> somehow magically becomes <code>CALL 416537</code>? I don't see any <code>416537</code> in the opcodes. Found this answered here, leaving it for reference: <a href="https://stackoverflow.com/questions/10376787/need-help-understanding-e8-asm-call-instruction-x86">https://stackoverflow.com/questions/10376787/need-help-understanding-e8-asm-call-instruction-x86</a>.</li> <li>At the <code>MOVS</code> instruction where the exception is raised before ending up in the exception handler, if I press <code>Shift-F7</code> or <code>Shift-F8</code> to single-step instead of <code>Shift-F9</code> I somehow end up at 4E3137 which is full of <code>ADD BYTE PTR DS:[EAX], AL</code> instructions, presumably an area of filler instructions that will later be overwritten. How come I ended up here? If I try to keep stepping I'm told <code>EIP</code> is set to <code>00000000</code> and can't proceed. This seems to be the case whenever I choose to exception-single step; errors show up that would be smoothly ignored if I had just used <code>Shift-F9</code>.</li> </ol> <p>I have the same problem in OllyDbg 2.01 aswell.</p>
Why doesn't Olly's analyzation work properly in this code section?
|ollydbg|unpacking|
<p>A fat header is the header of a fat binary.</p> <p>See <a href="http://books.google.com/books?id=K8vUkpOXhN4C&amp;pg=PA67" rel="noreferrer">pages 67-68 in <em>Mac OS X Internals</em></a>:</p> <blockquote> <p>Note that a fat binary is essentially a <em>wrapper</em>—a simple archive that concatenates Mach-O files for multiple architectures. A fat binary begins with a fat header (<code>struct fat_header</code>) that contains a magic number followed by an integral value representing the number of architectures whose binaries reside in the fat binary.</p> <p>...</p> <p><img src="https://i.stack.imgur.com/XhELz.png" alt="fat header"></p> </blockquote>
6356
2014-10-01T15:20:57.683
<p>Today I saw a command line option in the output of <strong>otool</strong> (this is a MacOS X program, offering similar functionality as <code>objdump</code>) that is named: </p> <pre><code>-f -- print the fat headers </code></pre> <p>So, what are the <strong>fat headers</strong> ? </p> <p>I tried to Google '<em>fat headers</em>' and '<em>fat headers elf</em>' but didn't find anything useful. </p>
What is a FAT header?
|tools|
<p>This is dean edwards' js packer : <a href="http://dean.edwards.name/packer/" rel="nofollow">http://dean.edwards.name/packer/</a>. I see it quite frequently being used to obfuscate scripts as it is freely available. It's written in Javascript but there are also versions in other langages on the site.</p> <p>By the way the Decode button and text area is only disabled via HTML attributes, so you can reenable them using The Developer Tools in Google Chrome for example :) Here are the 2 decoded scripts from your sample :</p> <p><a href="http://pastebin.com/duWWwWuQ" rel="nofollow">http://pastebin.com/duWWwWuQ</a> <a href="http://pastebin.com/VUaivSVk" rel="nofollow">http://pastebin.com/VUaivSVk</a></p>
6358
2014-10-01T16:18:50.690
<p>I have read about <a href="https://reverseengineering.stackexchange.com/questions/1436/analyzing-highly-obfuscated-javascript?lq=1">de-obfuscating JS files</a> and about <a href="https://reverseengineering.stackexchange.com/questions/2103/try-to-deobfuscate-multi-layered-javascript?lq=1">multi-layered obfuscation</a>. I have come across a file (which I have uploaded <a href="http://pastebin.com/2GUWbLsY" rel="nofollow noreferrer">here</a>) and it doesn't seem to be obfuscated except for lines 21 and 42. I there seems to be some HTML components on those lines but when I tried using JSBeautifier and JSDetox on it, it doesn't help. </p> <ol> <li><p>Have any of the reverse engineers come across this type of obfuscation? if yes, how is it done?</p></li> <li><p>Is thereany way to de-obfuscate it?</p></li> </ol>
What kind of JS obfuscation is this?
|obfuscation|deobfuscation|javascript|
<p>This is a straightforward translation of </p> <pre><code>x = foo; doSomething(x); </code></pre> <p>An optimization pass would have realized that <code>x</code> was still in <code>r0</code> here. Presumably optimizations were turned off.</p> <p>By the way, it's not <em>that</em> wasteful, as the memory location in question will still be in L1 cache.</p>
6361
2014-10-01T21:29:39.807
<p>I have this small subroutine (from Hopper, but IDA is similar):</p> <pre><code> sub_stringbegin: 000127b8 push {r11, lr} 000127bc add r11, sp, #0x4 000127c0 sub sp, sp, #0x8 000127c4 str r0, [r11, #-0x8] 000127c8 ldr r0, [r11, #-0x8] 000127cc bl _ZNSs5beginEv@PLT 000127d0 mov r3, r0 000127d4 mov r0, r3 000127d8 sub sp, r11, #0x4 000127dc pop {r11, pc} ; endp </code></pre> <p>The parameter is passed to this in r0.</p> <p>Why is this stored into the stack frame then immediately read out? It seems wasteful.</p> <p>I understand that r0-r3 aren't preserved in the ARM calling convention, but in that instance it would be sufficient to either just store it in the stack frame or pop it onto the stack.</p> <p>Similarly, moving r0 into r3 and back again seems wasteful after the branch.</p> <p>This is a ELF executable from a Busybox system. </p>
Why does this ARM subroutine put a parameter into the stack frame and take it straight back out?
|disassembly|arm|
<p>The data at <code>00401120</code> is ASCII-encoded text:</p> <pre><code>3C 2F 66 6F 6E 74 3E 3C 2F 70 3E 00 52 4E 3A 25 &lt;/font&gt;&lt;/p&gt;.RN:% 73 20 52 54 3A 25 73 20 55 3A 25 73 20 50 3A 25 s RT:%s U:%s P:% 77 6C 65 00 3D 22 62 61 63 6B 67 72 6F 75 6E 64 wle.="background 73 0D 00 00 s... </code></pre> <p>You can tell IDA to decode those bytes as text by clicking on the data at <code>00401120</code> and pressing the <kbd>A</kbd> key</p>
6368
2014-10-03T15:04:15.470
<p>I have the following two lines:</p> <pre><code> .... push 401150h call sub_401253 .... </code></pre> <p>So, when I click on <strong>push 401150h</strong> IDA PRO shows:</p> <pre><code> seg0001 : 00401120 dword_401120 dd 6F662F3Ch, 3C3E746Eh, 3E702Fh, 253A4E52h, 54522073h dd 2073253Ah, 73253A55h, 253A5020h, 656C774h, 616223Dh, 72676B63h, 646E756Fh dd 0D73h, 7320703Ch, 335504h, 7265464h, 5484531h 55E4ADEh, A585B5448h, .....(and so on) </code></pre> <p>So, my first question would be : what is this? what it can be?</p> <p>My own results: that thing which I mentioned above is a string because in the function sub_401253 they copy it using lstrcpy() into a buffer:</p> <pre><code> ... lea eax, [esp+1FC + Buffer] ... mov edi, [esp+208+arg_0] push edi, push eax, call lstrcpy ... </code></pre> <p>After that, in a next block the content of the buffer(which are the hexadecimal numbers now) is XORed in a loop. I assume that they encrypt or decrypt it (but that is not so importan for me right now.)</p> <p>I only want to know what IDA PRO try to depict with <strong>push 401150h</strong> which represents the hexadecimal numbers. Thats it. I hope you can help me.</p> <p>best regards,</p>
PUSHing a lot of hexadecimal numbers
|ida|assembly|hexadecimal|
<p>If you run across an API call that you're unfamiliar with, check the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms683212(v=vs.85).aspx" rel="nofollow">MSDN page</a>. Parameter 2 is "The function or variable name, or the function's ordinal value." Looking at your offset only one of those things is a function name, WNetEnumCachedPasswords.</p> <p>You can verify this as the comment in your post said, by counting 12 (0xc) bytes from aPstorec_dllwne. db stands for databyte and you can also see that "char aPstorec_dllwne[]" designates a character array, also 1 byte per element.</p>
6371
2014-10-04T10:23:46.430
<p>I have the following line (I use IDA PRO) :</p> <pre><code> ... push (offset aPstorec_dllwne+0Ch) ; lpProcName push esi ; hModule call GetProcAddress_0 ... </code></pre> <p>When I click on <strong>(offset aPstorec_dllwne+0Ch)</strong> I use:</p> <pre><code> seg001:004012F0 ; char aPstorec_dllwne[] aPstorec_dllwne db 'pstorec.dll, 0 , 'WNetEnumCachedPasswords', 0 , 'MPR.DLL' , 0 , 'SeDebugPrivilege', 0 , 0 , 0 , 0 </code></pre> <p>So my question is: How should I read it to get the info which process is meant? I know that each field of an array is 4 byte and the <strong>db</strong> at the beginning indicates that. But when I count from zero, I come to the 0 after WNetEnumCachedPasswords. It is wrong, right?</p> <p>best regards</p>
Using GetProcAddress with offset syntax
|assembly|array|offset|process|call|
<p>OllyDbg2 supports this.</p> <hr /> <p>Another possibility of forcing ASLR off to get the same bases every time a DLL is loaded did not work for me. For those who want to try it: Start a Visual Studio Developer prompt (yeah, you'd need VS) and type in</p> <pre><code>editbin /DYNAMICBASE:NO C:\Game\game.exe </code></pre> <p>It should modify the PE header to disable ASLR in that executable and all DLLs it loads. But as said, it had no effect for me.</p>
6376
2014-10-04T12:31:02.597
<p>My program loads and unloads a DLL of main interest at runtime. I try to add comments and labels to the DLLs code, but when it is unloaded and loaded again, they are gone, as the DLL is rebased most of the time.</p> <p>I'm in search for an OllyDbg plugin to preserve the comments and labels when a DLL gets rebased (for Olly 1, but this task is that important that I'd also switch to Olly 2 if there is a plugin only for 2).</p> <ul> <li>I tried <a href="http://www.openrce.org/downloads/details/107/Labelmaster" rel="nofollow">Labelmaster</a>, it can export and import comments and labels into text files. But the addresses in the textfiles are completely static and do not respect rebased DLLs.</li> <li>A forum user <a href="http://www.blizzhackers.cc/viewtopic.php?f=71&amp;t=310891&amp;start=0" rel="nofollow">posted a plugin named "Dynamic Debugging"</a> which would solve my problems as it can load stored comments and labels with a base address I can manually specify. However, the thread is from 2006, and the download cannot be found on the net anymore, not even in archives.</li> </ul> <p>Anyone knowing a plugin or still having the "Dynamic Debugging" plugin?</p>
OllyDbg: Keep comments & labels in rebased DLL
|ollydbg|binary-analysis|
<p>One thing that I've failed to notice turned out to be crucial: this file wasn't generated by my copy of IDA, it was given to me by a friend as a helping resource. I've simply disassembled the very same exe with my IDA and the troublesome address is now correct:</p> <p><img src="https://i.stack.imgur.com/i2Y5o.png" alt="enter image description here"></p> <p><img src="https://i.stack.imgur.com/fK3Bo.png" alt="http://i.imgur.com/AzHGbT1.png"></p>
6377
2014-10-04T13:18:23.310
<p>In an application I'm analyzing, there's a global variable whose purpose/role in the program is known to me. I'd like to rename it, but for some reason I cannot.</p> <p>The assembly code:</p> <pre><code>.text:00537E90 mov edx, ds:1C968D8h .text:00537E96 mov [eax], edx .text:00537E98 mov ds:1C968D8h, eax </code></pre> <p>If I position the cursor on the address (<code>ds:1C968D8h</code>) and try to jump (using Enter), IDA will complain <code>Command "JumpEnter" failed</code>. Attempting to rename it with the N hotkey will cause IDA to place a label at that address rather than rename the variable as intended.</p> <p>While I'm doing this for educational purposes, this is a proprietary application, so I don't have the source code.</p> <p>I've checked Chris Eagle's "The IDA Pro Book", but there seems to be nothing on the subject in there.</p> <p>Help is greatly appreciated.</p>
IDA - cannot rename or jump to a global variable
|ida|
<p>You should try to find out which compiler/library is being used, then check the specs of that compiler.</p> <p>Assuming it's <code>gcc</code> with <code>libstdc++</code> (this is quite probable if you're on android; less probable on Windows RT), googling for "gcc libstd ios_base openmode" yields <a href="https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-api-4.5/a00504.html" rel="nofollow">https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-api-4.5/a00504.html</a>, which tells it's defined in ios_base.h. Navigating there, you can find </p> <pre><code>00112 enum _Ios_Openmode 00113 { 00114 _S_app = 1L &lt;&lt; 0, 00115 _S_ate = 1L &lt;&lt; 1, 00116 _S_bin = 1L &lt;&lt; 2, 00117 _S_in = 1L &lt;&lt; 3, 00118 _S_out = 1L &lt;&lt; 4, 00119 _S_trunc = 1L &lt;&lt; 5, 00120 _S_ios_openmode_end = 1L &lt;&lt; 16 00121 }; </code></pre> <p>and</p> <pre><code>static const openmode in = _S_in; </code></pre> <p>so the open mode is probably <code>in</code>.</p> <p>But, unless you find out which compiler was used, this a guess, and we can only help you guessing.</p>
6381
2014-10-05T10:09:09.287
<p>I am working on some ARM disassembly. A file is being operated on:</p> <pre><code>0000e550 sub r3, r11, #0x2d0 0000e554 mov r0, r3 ; /tmp/MAC 0000e558 ldr r1, = 0x9a60c ; 0xec04 (sub_e3a8 + 0x85c) 0000e55c mov r2, #0x8 ; std::basic_fstream&lt;char,std::char_traits&lt;char&gt;&gt;::basic_fstream(char const*,std::_Ios_Openmode) 0000e560 bl _ZNSt13basic_fstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode@PLT ; std::basic_fstream&lt;char, std::char_traits&lt;char&gt; &gt;::basic_fstream(char const*, std::_Ios_Openmode) </code></pre> <p><code>r0</code> is "<code>this</code>", <code>r1</code> is the path (<code>/tmp/MAC</code>) and <code>r2</code> is the mode. As can be seen, the mode is <code>0x8</code>. </p> <p>The mode is "implementation defined" according to <a href="http://en.cppreference.com/w/cpp/io/ios_base/openmode" rel="nofollow">several sources</a>. I haven't got specifics of the implementation unfortunately. </p> <p>What is the typical implementation of this on ARM ?</p>
How do I map the std::_Ios_Openmode passed to basic_fstream to an actual value?
|disassembly|c++|arm|
<p>I happen to just run into this exact issue.</p> <p>Here's what I did. Replace the <code>for</code> bits with the <code>if</code> bits to just test it on a small bit.</p> <pre><code>from idautils import * from idaapi import * from idc import * #if True: # if True: # if True: # startea = 0x0F9109DC # endea = 0x0F9109F for segea in Segments(): for funcea in Functions(segea, SegEnd(segea)): functionName = GetFunctionName(funcea) for (startea, endea) in Chunks(funcea): for ea in Heads(startea, endea): if idc.GetMnem(ea) != "MOV" or idc.get_operand_type(ea, 1) != 5 or idc.get_str_type(idc.get_operand_value(ea, 1)) != 0: continue print "0x%08x"%(ea), ":", idc.GetOpnd(ea, 1), idc.get_operand_type(ea, 1) idc.op_plain_offset(ea,1,0) </code></pre> <p>```</p>
6384
2014-10-05T15:32:39.120
<p>I working with ARM executable. Sometimes I have something like this <code>MOV</code> instruction:</p> <pre><code>MOV R0, #0xCD548A40 </code></pre> <p>where the number <code>#0xCD548A40</code> is a valid offset but IDA doesn't recognize it as such automatically. I tried to reanalyze the executable with enabled option &quot;<em>Automatically convert data to offsets</em>&quot; without of any suitable result. I also tried to write IDAPython script to fix this, but the only possibility of conversion to offset that I found was:</p> <pre><code>idaapi.jumpto(address) idaapi.process_ui_action(&quot;OpOffset&quot;, 0) </code></pre> <p>Which is not too much convenient to use.</p> <h2>Question</h2> <blockquote> <p>Given an instruction at specific address and one of its operands in a valid offset range is it possible to convert such numbers to offsets using IDA Python ?</p> <p>Which IDAPython API should I use for it ?</p> </blockquote>
Making operand an offset in IDA Python
|idapython|
<p>If the memory address is constant you can attach to the process and use the awatch command on GDB to monitor it. If it's not static you can break on the offending malloc call and set the bp there.</p>
6390
2014-10-06T21:04:56.960
<p>I want to be able to monitor when a memory address is read from on Android. The binary I am studying stores around 60 bytes to a memory location during initialisation and this buffer is used at some later point. My problem is that I can't seem to find where this is accessed by static analysis and would like to set a breakpoint so that I can track its access during runtime.</p>
Break on memory access on Android
|ida|memory|android|
<p>Since the original LabelArgs plugin was open source, I ported it to OllyDbg 2. It should have the same functionality as the original LabelArgs plugin, feel free to improve on it.</p> <p>Link to the repository: <a href="https://bitbucket.org/mrexodia/labelargs" rel="nofollow">https://bitbucket.org/mrexodia/labelargs</a></p> <p>Binaries: <a href="https://bitbucket.org/mrexodia/labelargs/downloads" rel="nofollow">https://bitbucket.org/mrexodia/labelargs/downloads</a></p>
6398
2014-10-07T20:17:51.937
<p>I recently switched from OllyDbg 1 to 2, and I'm really missing a feature the plugin "LabelArgs" provided to me in OllyDbg 1.</p> <p>Labels were extended in a way it was possible to name the first instruction of an obvious functions like "WriteToLog(int portOrOther, string title, string category, string text, int severity)". In the disassembly, calls to the functions then appeared visually like calls to known WinAPI methods, for example: <img src="https://i.stack.imgur.com/jYRep.png" alt="enter image description here"></p> <p>In OllyDbg 2 it looks like: <img src="https://i.stack.imgur.com/VDgLt.png" alt="enter image description here"></p> <p>Sadly strings are not directly seen anymore, but it helped me much more seeing when pushes are about to be method parameters.</p> <p>Is there an OllyDbg 2 compatible plugin providing me this feature?</p>
OllyDbg 2: Providing label arguments?
|ollydbg|
<p>I've seen 4 naming conventions being used: </p> <ul> <li>vNNN() when decompiling ARM binaries (i.e.: Android JNI code) - not sure how it numbers them as it doesn't seem it's related to their position or address within the binary.</li> <li>sub_HHHHHH() when decompiling x86/64 binaries (i.e.: for Windows, OSX) with the actual address on the name</li> <li>_name/__name() for functions IDA is able to identify via its FLIRT algorithm</li> <li>finally the clear names for functions it has enough information on the binaries to reverse as they were named originally.</li> </ul>
6399
2014-10-07T21:05:36.727
<p>I am using IDA pro to decompile a series of applications. These applications share a common feature and what I have found is that in each decompilation each application shares the same set of functions. If the binary is stripped how does IDA pro work out the function names ? </p> <p>The functions that I am seeing in common between the applications are all very abstract, for example <code>v404()</code>, and as far as I can work out don't come from any open source library set of functions.</p>
How does IDA pro generate function names?
|ida|decompilation|functions|symbols|debugging-symbols|
<p>Depending on the worker model your apache is configured to use its likely a new worker is being spawned to handle your request if your bp isnt hitting. Like Guntram said you can <a href="https://httpd.apache.org/dev/debugging.html" rel="nofollow">disable forking</a> and put httpd in debug mode by using the <code>-X</code> flag and starting gdb with:</p> <pre><code>gdb httpd -X </code></pre> <p>If for some reason you need to debug the multiple worker configured httpd you should use the gdb options <code>set follow-fork-mode ask</code> or <code>set follow-fork-mode child</code> if you know you'd like to follow all forks in advance. (<a href="https://sourceware.org/gdb/onlinedocs/gdb/Forks.html" rel="nofollow">https://sourceware.org/gdb/onlinedocs/gdb/Forks.html</a>). This would also be considered the 'generic approach' and would apply to programs that don't allow you to run single process in the foreground.</p>
6400
2014-10-07T22:04:20.413
<p>I'm attempting to inspect memory of an httpd binary compiled statically with openssl. When I list the httpd processes, I get:</p> <pre><code>$ ps aux|grep httpd root 58539 0.0 0.7 75364 3740 ? Ss 14:49 0:00 /opt/httpd/bin/httpd daemon 58850 0.0 0.5 364328 2556 ? Sl 14:58 0:00 /opt/httpd/bin/httpd daemon 58914 0.0 0.5 364328 2548 ? Sl 14:59 0:00 /opt/httpd/bin/httpd daemon 58942 0.0 0.5 364328 2544 ? Sl 14:59 0:00 /opt/httpd/bin/httpd </code></pre> <p>I then tried attaching to each of the processes individually and applying a breakpoint to the function I am trying to debug. However, the breakpoint never gets triggered, although I know the function is being called. I assume this problem relates to something along the lines of httpd forking on a new process, but I'm a bit stuck on how to proceed. Is there a generic way to ensure my breakpoint is triggered even if the processes forks?</p>
Debug httpd process
|gdb|dynamic-analysis|
<p>To answer your other question, maxphyaddr and the AMD counterpart are found via cpuid leaves, but it's important to note that the bus interface to the MCH (which is typically integrated on the cpu these days) probably only uses 33-36 of those lines on the address bus.</p>
6406
2014-10-08T16:23:42.553
<p>The !pte command in WinDbg gives all the information one may need regarding a virtual address (PDE and PTE location and content), but even on systems with PAE it says nothing about the Page Directory Pointer Table. I know that I can get the physical base of the PDPT by looking at CR3, and then use the highest 2 bits of the VA as a index in that table to get to the PDPT Entry, but I'm just curious if there is a command that works like !pte when it comes to PAE as it will be a nice tool to verify my address translations step by step. </p> <p>Also, is there a way to determine MAXPHYADDR? I know it is at most 52. </p>
Page Directory Pointer Table in WinDbg
|memory|windbg|
<p>There are a few really great options.</p> <p>First, something that I frequently forget when doing patching is that <code>LD_PRELOAD</code> makes hooking/redirecting library routines very easy.</p> <p>If you must patch instructions, the tools that I use on a regular basis are <a href="https://github.com/Gallopsled/pwntools" rel="nofollow noreferrer"><code>pwntools</code></a> (a Python library) and <a href="https://isisblogs.poly.edu/2014/04/02/the-other-kind-of-patch/" rel="nofollow noreferrer"><code>Fentanyl</code></a> (an IDAPython script).</p> <p>For <code>pwntools</code>, the following would be an example of patching an instruction at file-address 0x1234, which we'll say is virtual-address 0x8001234. Note that this support is limited to ELF files, and does not work for PEs.</p> <pre><code>#!/usr/bin/env python from pwn import * file = ELF('/path/to/elf') file.asm(0x8001234, 'nop') # Using virtual address file.asm(file.offset_to_vaddr(0x1234), 'nop') # File offset file.save('/path/to/output') </code></pre> <p>Using Fentanyl is GUI-driven, but it works pretty well and even nop-pads your instructions and fixes offsets.</p> <p><img src="https://i.stack.imgur.com/YsyMG.gif" alt="Fentanyl demo"></p>
6419
2014-10-10T19:33:44.593
<p>I've recently been undertaking a little RE project where I needed to patch the executable. For small modifications, I know enough x86 to patch in an jump, nop, infinite loop, etc, so a hex editor is good enough. But what about larger ones? </p> <p>I used to use OllyDbg for this, there were great tools in it, you could go to any line, press space and just start assembling, instructions you replaced would be padded with NOPs automatically and there were even nice plugins to find code caves. </p> <p>Unfortunately, OllyDbg seems barely updated these days and fails to load any application on 64 bit Windows 8.1, so I've switched to Hiew. Hiew isn't bad, but the interface is well, more than a little dated and fairly cumbersome to use compared to Olly's. </p> <p>I'm wondering if anyone knows any more modern tools that can perform this same sort of function. </p>
Are there any modern assembly-level patching tools?
|ollydbg|patching|
<p>due to optimizations which include chunking of functions the offsets in the symbols are rendered irrelevent use actual address to set breakpoints windbg normally shows the actual address in brackets at the end</p> <p>for example some random function in msxml</p> <pre><code>0:007&gt; ? msxml3!AbortParse Evaluate expression: 1956897309 = 74a3e21d 0:007&gt; # je msxml3!AbortParse l10 msxml3!AbortParse+0x18: 74a3e235 7451 je msxml3!AbortParse+0x61 (74a3e288) 0:007&gt; bp msxml3!AbortParse+0x61 0:007&gt; bp 74a3e288 0:007&gt; bl 0 e 74a3e27e 0001 (0001) 0:**** msxml3!AbortParse+0x57 1 e 74a3e288 0001 (0001) 0:**** msxml3!AbortParse+0x61 0:007&gt; .bpcmds bp0 0x74a3e27e ; bp1 0x74a3e288 ; </code></pre>
6420
2014-10-10T19:40:10.940
<p>As part of an assignment, I am trying to do some debugging in <code>iexplore.exe</code> (Aurora vulnerability).</p> <p>After I load the test webpage in iexplorer 8, I open windbg and attach to the iexplore process.</p> <p>I verify my symbolpath by using:</p> <pre><code>.sympathy Symbol search path is: srv*C:\Users\User\Desktop\Symbols Expanded Symbol search path is: srv*c:\users\user\desktop\symbols </code></pre> <p>I know that what I am interested in is inside of <code>mshtml</code>, so I list all the symbols in mshtml via:</p> <pre><code>x /t /n mshtml!* </code></pre> <p>Next, I use:</p> <pre><code>u mshtml!CEventObj::GenericGetElement </code></pre> <p>To see the function I am interested in and discover that one of the instructions I want to examine is at:</p> <pre><code>mshtml!CEventObj::GenericGetElement+0x91 </code></pre> <p>I try setting a breakpoint at that address by:</p> <pre><code> bp mshtml!CEventObj::GenericGetElement+0x91 </code></pre> <p>Then, I run:</p> <pre><code>bl </code></pre> <p>And the breakpoint shown is actually at:</p> <pre><code>mshtml!CEventObj::GenericGetElement+0x3b </code></pre> <p>Why isn't my breakpoint at the point I specified ?</p> <p>Also I have tried using:</p> <pre><code>u mshtml!CEventObj::GenericGetElement+0x91 </code></pre> <p>And the code is totally different than when I simply unassembled the entire function based on the symbol address for the function.</p> <p>Any ideas would be greatly appreciated.</p>
windbg refferencing symbols is inconsistent
|windbg|
<p>Debug the loader.</p> <p>Set a breakpoint on <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx" rel="nofollow"><code>CreateProcess</code></a> <em>(or <a href="http://undocumented.ntinternals.net/source/usermode/undocumented%20functions/nt%20objects/process/ntcreateprocess.html" rel="nofollow"><code>ZwCreateProcess</code></a> if needed)</em></p> <p>When the breakpoint is hit modify the <em><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms684863(v=vs.85).aspx" rel="nofollow">process creation flags</a></em> on the stack to include <code>CREATE_SUSPENDED</code>. Make sure to remove any debugging related flags such as <code>DEBUG_ONLY_THIS_PROCESS</code> etc.</p> <p>Single step over the <code>CreateProcess</code> call. At this point, the child process would be created in a suspended state. Now you should be able to attach a debugger to this.</p>
6427
2014-10-11T15:14:43.567
<p>I have a target application protected with CrypKey. When i try to attach to the apps in OllyDbg and Ida Pro i receive Unable to attach to this process.</p> <p>The bad news is that i want to unpack the main exe after executing of Crypkey loader but after patching main exe and loader to obtain an infinite loop at the end of the code of the loader i am unable to attach to main exe and reach the OEP.</p> <p>Do you know how or why i am unable to attack? A good solution in this cases?</p> <p>Thank you very much</p> <p>See image below:</p> <p><img src="https://i.stack.imgur.com/vec2o.png" alt="enter image description here"></p>
Ollydbg and IDA Pro unable to attach to process
|ida|ollydbg|anti-debugging|
<pre><code>alt + k -&gt; right click -&gt; copy to clipboard whole table -&gt; paste to notepad -&gt; save </code></pre>
6430
2014-10-11T16:14:53.317
<p>Is there a way to dump the stack of a program while debugging in ollydbg and store the result in a file ? </p>
Dump the stack in Ollydbg
|ollydbg|stack|
<p>UML diagrams, function traces, and data flow maps won't be able to produce a high-level architecture design specification for a complex system. No automated software exists to produce the type of design specification for which you're looking.</p> <p>The solution is to read the existing code and documentation (or pay somebody else to do it), or to talk with the original developers/designers of the software.</p>
6434
2014-10-12T17:47:50.137
<p>I am attempting to recover the architecture for an open source application (Written in Java). Obviously I have looked at the available documentation but it has not given me the detail that I need to know. I would like to know what would be the best approach or the most used approach to solve this problem.</p> <p>I have heard that using request traces would be a good place to start (using something like btrace)? So lets say that the application is a basic web server would you make basic http request while doing the request tracing and then draw a sequence diagram from the data to visualize the process?</p> <p>I have also heard that generating a uml diagram from the source could be usefull? The project in question has over 300 classes so how would you proceed in generating the diagram, which parts of the system and which diagrams (class diagram maybe)?</p> <p>Also are there any other methods that are know to be effective that I should try specifically for a java application that sends and receives requests across a network?</p> <p>I am just trying to get a general direction to follow, or a pointer to a process that generally works well or any advice that would make the process easier.</p> <p>Thanks in advance</p> <p><strong>EDIT:</strong></p> <p>What I hope to achieve is a high level architecture design specification for the system. This includes architectural patterns as well as tactics used to achieve specific non-functional requirements (caching for performance). This is what the architecture currently looks like. It should be possible to, from the design spec, analyse the architecture and extend or change the design to possibly improve it or to cater for different non-function requirements.</p>
Recover architecture. Open source application
|java|
<p>A derived class will get its own <code>vtable</code> if it overrides any of the virtual functions.</p> <p>If the derived class does not override any virtual functions, it will use the original <code>vtable</code>.</p> <p>I would say that your assumption is correct ~90% of the time.</p> <p>The best that you can do for <em>static</em> type recovery, is to look at the <code>vtable</code> being used.</p> <p>What you can do to help a bit is to turn one PageHeap with stack tracking (<code>gflags.exe /i iexplore.exe +hpa +ust</code>) and look at the address allocated for the object (<code>!heap -p -a 0xaddress</code>). This will give you a full stack trace to the allocation-site of the object, which is sometimes to determine the type of object (e.g. if a <code>Factory</code> pattern was used).</p> <p>Finally, there are additional dynamic analysis tricks you can play. I wrote a Pin tool and IDA Python plugin, <a href="https://github.com/zachriggle/ida-splode" rel="nofollow noreferrer">ida-splode</a> for almost exactly this application. By capturing information at runtime, you can enhance your IDA traces. Below is an example screenshot from the slide deck. The better symbol information you have (or the better fleshed-out your IDB is), the better the information you get.</p> <p><img src="https://i.stack.imgur.com/A0XBu.png" alt="enter image description here"></p>
6436
2014-10-12T20:05:06.883
<p>As part of an assignment, I am delving into the world of Internet Explorer, and am trying to figure out exactly what class(es) are being allocated on the heap.</p> <p>In the <code>mshtml!CEventObj::GenericGetElement()</code> method, the <code>eax</code> register points to an instance of a class, <code>edi</code> points to the object it references, and <code>esi</code> points to the vftable.</p> <p>This being said, I inserted a breakpoint that would list these registers each time through the function, and they always point to the same vftable.</p> <p>The vftable in question is <code>mshtml!CBodyElement</code>, but does this actually mean that all these instances are of the <code>CBodyElement</code>, or could they be for classes derived from <code>CBodyElement</code>. </p> <p>If they are from derived classes, how do I determine the actual classes being allocated ?</p>
Windbg: going from vftable to c++ class
|dynamic-analysis|windbg|
<p>This is how it works at .NET. When the method is compiled a table is generated that contains the information (including offset, length) to match MSIL code to their machine code counterparts. However not all MSIL instructions have meaningful machine code counterpart, instead the table contains the info to match a sequence of MSIL instructions (block) to the machine counterparts.</p> <p>You can access the table via Debugging or Profiler interface, or as I did, you can reverse engineer.</p> <p>I'm not sure if such table exists in Flash, and if so is there a way to get it via documented function calls. But this should be one technique to consider.</p>
6444
2014-10-14T03:48:04.193
<p>There are lots of programs I seen that can locate a swf running in memory, capture it and return source code. Usually the AS byte code is generated as well.</p> <p>What I looking to do is the opposite, I'm trying to match a section of Action Script byte-code to a section of disassembly from a Shockwave Flash program. </p> <p>Basically match p-code to disassembly.</p> <p>Is there any good techniques or software that can do this.</p>
Matching ActionScript byte code to the Disassembly of a Shockwave Flash
|assembly|byte-code|actionscript|
<p>Just like in your sample program, the signal handlers are installed using a <code>signal</code> (or <code>sigaction</code>) function. So you just need to find the call to that function and see what argument is passed to it. That argument will be the address of the signal handler.</p>
6448
2014-10-14T13:46:50.143
<p>I'm reversing a program that uses a lot of <code>BREAK</code>/<code>int 3</code> (Linux). I guess that the code contains something like:</p> <pre><code>void sigtrap_func(int sig) { (some stuff..) } int main() { signal(SIGTRAP, sigtrap_func); (some stuff) asm("int 3"); (and so on) asm("int 3"); etc.. </code></pre> <p>I replaced all <code>SIGTRAP</code> by <code>NOP</code>s and the program behave differently than with them. So, I'm sure that something is done inside the <code>sigtrap</code> function.</p> <p>How can I find this function just with the assembler ?</p>
Find sigtrap function
|linux|anti-debugging|
<p>There are already a lot of great answers. If I may add my two cents. Reverse engineering software is akin to the mechanic or tinkerer whom just enjoys taking things apart, understanding how they work, putting them back together, and possibly modifying their subject to adapt its behavior so it is more to their liking. There is no shortage of examples in the physical realm.</p> <p>Any Electrical Engineer, hardware designer, and the most eliete QA engineers are talented reverse engineers; which is to say, they have an expertise in debugging/analyzing software/hardware implementations. I interned at AMD as I worked my way through school and my debugging skills not only helped me advance to more serious roles within the company, but it is also <em>really</em> fun! Like a game or puzzle that you can play for as long as you want. The challenges will never stop coming.</p> <p>My favorite example of a legitimate need for reverse engineers is NASA. They are not the only outfit where the phrase "mission critical" applies, where people's lives depend on the quality of their work, but it is the only one that has to fix problems even if their product is hurtling through space. They have to set and freeze product versions <em>years</em> before that software / hardware ever goes to the launch pad. That may seem silly, because the phones in our pocket have more computing power than the entire shuttle, but they can't use modern technology. It's too risky. They have to accept what is available at the time that the specs are frozen and that's it - lest they incur the scheduling and workload that upgrading, testing, fixing, re-testing, verifying again, simulating realistic conditions to determine failure points, fixing it, and starting over.... it is serious business and those engineers do not take their responsibility lightly.</p> <p>Would you be surprised to learn that NASA projects have used Microsoft OSes on hardware went into shuttle components? It is not much different than using a M$ OS as the foundation for, say for instance, a point-of-sale terminal or for the control system at a power plant. Now consider a scenario where the OS, the hardware, or some portion of third-party software is found to have a flaw in it. Moreover, imagine that the vendor does not care about the flaw to the degree that NASA does and decides that there is no fiscal motivation for them to fix the issue - even if lives depend upon that component not failing. NASA is stuck.</p> <p>At this point their options are to either replace the component and start their processes all over - a huge cost in time, man-hours, and no guarentee that they won't discover another critical flaw after upgrading; or, instead of upgrading, they can reverse engineer the hardware/software failure and determine if they could fix the problem themselves - maybe it would take some curcuit re-design, changing the values of a few resistors so that voltage levels on the memory bus stayed within required limits under the extreme conditions that were making them fail or maybe there is a binary patch that they can apply that to mitigate the error state they discovered where life-support systems began failing or a probe's batteries drained and left it unable to re-charge itself.</p> <p>I'm not totally making these scenarios up. They come from stories I have been told, by friends who worked at JPL, my engineering professors when I was in the University, or colleagues that have worked with in the tech industry. All this, and more, has been surmounted by NASA's engineers. It did cost quite a bit more than India paid (tip of the hat to them too), to do what they have done, but the first time through is always more costly.</p> <p>Technically, NASA engineers would be violating one or more of the intellectual property laws that vendors claim they have (they may or may not actually have those rights; I"m not trying to debate that here). If you bought a corvette, you would be completely within your rights to bore out the cylinders to change your car's performance profile. Different tires. Modified suspension. Tweaked timing and mixture ratios in the fuel injection system. The famous Shelby Cobra is not only modified, but also remarketed with its aftermarket modifications- all entirely legal.</p> <p>If you bought a radio and wanted to make some modifications, so that it was water proof and you could take it on the lake with you. Amplify it's output so that it would still be audible over the boat engine, or anything of that sort... legal.</p> <p>Now, jailbreak your iPhone, modify your xBox or the Kinect system that came with it, or, in NASA's case, modify the OS and/or re-engineer the memory bus on a motherboard, to ensure the safety of a human mind you. All of these activities have evoked fierce reactions from the vendors that, for whatever their reasoning, do not want those activities to be continue nor become more widespread. Ultimately, this led to the DMCA laws that we have today being passed. Before that, even if you were clicking "I agree" to the rediculus terms and services that were put before you there was still the question if that contract was legal enforceable. </p> <p>The DMCA, which does nothing to disuade the massive blackmarkets in China or South America, carries harsh penalties and has been treated as a kind of "hunting license" for those that wish to go after consumers can and have. Should it be illegal to make unlicensed copies of someone elses music; to sell, trade, or even give it away? </p> <p>Clearly, that should be illegal. Artwork, books, patented processes, protected trademarks; yes, those should be protected too. Software and hardware; again, yes the the author of software should be able to enforce resonalbe aspects of their licensing that protect the the investment that have made to create said software or hardware. Explicitly, it is, and should remain, illegal to puchase one copy legitimately, turn around and make copies, and then sell/trade/or give the unlicensed copies. Microsoft, VMWare, Adobe, and similar big companies should retain that right. </p> <p>Now, once I have licensed the software or hardware can I make modifications and then sell/trade/or give away the software/hardware that featured <em>my</em> modifications. That depends. It i, and should be illegal, to profit from derivatives works beyond the limit to which you originally licended the art (i.e. software). For example, you could not draw the likeness of a Disney character, change the name, and then claim it as your own and profit from it's use. I believe that Mikey no longer protected, but when he was that was and should be illegal.</p> <p>Should a computer hobbyist, like the ones that we credit for founding the industry today, be allowed to to explore, tinker, change, discuss, show, or teach any manner of activity that they desire on their legally licensed software and hardware? I won't answer that, but I will say that the DMCA says "no". In fact, the same tools that a reverse engineer would use for debugging the operating system are the very same tools that the prosecution will cite as evidence of illegal activity.</p> <p>Let's be a little more giving for someone prosecuting a DMCA case where the accused was know to have accessed the cryptographic keys that, among other things, would allow the defendant to make copies of protected art (e.g. music and movies). There are some legitimate reasons that could explain the defendants actions, but not many and the illegal activities that could be pursued are costly to those that are trying to protect themselves. At the end of the day, even though they tried their best, there is no way to actually prevent anyone from accessing those cryptographic keys.</p> <p>It reminds me of the tag on a mattress waring of insanely harsh penalties for removing said tag, but there is no protection for the tag. Just threats and overreaching penalties that are used to make examples out of as they stoke the fire and declare a witch hunt.</p> <p>Should Apple be able to prosicute a security research whom respectfully, and sincerely trying to help and support Apple make better products, be prosicuted by the technology giant? Hell no, but you better believe that they tried - that happened. The employees of Target or Home Depot that warned of potential dangers; where are they now? They were fired, run-off, considered a nuisance to the company, shunned, and labeled as "not a team player". In the wake of the data breaches that Target, Home Depot, and countless others (certainly at least one of these events has impacted your life) it is more apparent now than ever that reverse engineering is not only a right, but an aspect of our emerging social structure that is going to be needed more than ever to 1) protect the innocent consumers and digital citizens of the world like yourself and 2) hold accountable those whom are responsible to take reasonable measure to protect the community that entrusted them with their well being (granted in exchange for a service).</p> <p>The NSAs, the CIAs, the DeutcheBanks, the HealthCare.govs, and the hospitals that we all wanted and empowered to do what they have done. It is the reverse engineer who will become the modern freedom fighter, tomorrows activist, that is going to be on your side, the little guy, when power corrupts and greed lets way to disregard for the responsibilities that were implicit in the power granted to those organizations. To be just a bit more dramatic about it; reverse engineers are the priests of a new religion. We should honor them, applaud their bravery standing up to those drunk on power, and protect them when they risk the privacy of their family to step into the line of fire, on our behalf, because it is "the right thing to do".</p> <p>If you know one of these individuals- buy them a beer tonight and say thank you. As much as any soldier, they are going to be the ones that protect us when the next digital tragedy is impending.</p>
6455
2014-10-15T04:47:33.150
<p>At the professional level, for what purpose is reverse software engineering used? What software is targeted and why?</p> <p>For reasonably complex compiled code that's doing something novel, making meaningful insights into how that code operates via reverse engineering seems like it would be enormously intensive of expertise, labor, and time. In particular, I imagine that hiring competent assembly programmers is extremely difficult and possibly expensive. And yet, I haven't the foggiest idea where entities with the resources to do so would want to spend those resources.</p> <p>This is my list of possibilities...</p> <ol> <li>Writing malware</li> <li>Writing counter-malware</li> <li>Maybe analyzing competitors products?</li> </ol> <p>It's not a great list. What is the reality here? What sort of software justifies the expense to be reverse engineered?</p> <p><em>See the comments on 0xC0000022L's answer for some refinement of the question.</em></p>
What are the targets of professional reverse software engineering?
|disassembly|
<p>Well, without reject Igor Skochinsky's answer I want to post this more landed in the fact of <strong>how to find where compressed data is</strong>.</p> <p>Peter Kankowski wrote:</p> <blockquote> <p>NSIS authors found a fast solution using marker. It's so simple that you will say: &quot;Why didn't I think about it?!&quot;</p> <p>Just remember that data in an exe file is aligned by 512 or 4096 bytes. So you don't need to scan the whole exe for a marker, you just need to read 512-byte chunks and look for marker at their start. In pseudocode:</p> </blockquote> <pre><code>BYTE buff[512]; while(not end of file) { ReadFile( 512 bytes into buff) if(*(long*)buff == marker) { // Marker found! } // else read another 512-byte chunk in the loop } </code></pre> <blockquote> <p>I believe it's the simplest method; it's also faster than other methods with marker.</p> </blockquote> <p>So as you can see NSIS installer have some sort of marker. So, just look for the <code>ReadFile</code> API call, follow the program flow until the loops start again an watch for the last jump before the loop repeat it has to have a comparision around.</p> <p>And there you have the <strong>marker</strong>.</p> <p>If you want read more you can visit this very useful article: <a href="http://www.strchr.com/creating_self-extracting_executables" rel="nofollow noreferrer">Self-extracting executables</a>, thanks to Peter for a good adn clean explanation.</p>
6463
2014-10-15T13:02:12.167
<p>NISIS installers compress data using <code>bizp2</code>, <code>lzma</code> or <code>zlib</code> -- I don't know if there are others algorithms--.</p> <p>At some point in the installation process one of those algorithms has to be applied to certain buffer of data. Of course, that data was readed from the disk --contained into the installer--. </p> <p>How can I debug a NISIS installer in order to know where the installer files are? What I have to look for?</p> <p>Note: I can work with OllyDbg or IDAPro.</p>
How to debug a NSIS installer in order to find where the compressed data is?
|debugging|