Question

Interpreting some Assembly code

Asked by: thydzik

Code some one help me with what the following code is trying to achieve

Thanks

0A84:0210 8B5E06         MOV       BX,WORD PTR [BP+06]  
0A84:0213 0307           ADD       AX,WORD PTR [BX]  
0A84:0215 135702         ADC       DX,WORD PTR [BX+02]  
0A84:0218 2D885B         SUB       AX,5B88  
0A84:021B 81DA9528       SBB       DX,2895  
0A84:021F 0146FC         ADD       WORD PTR [BP-04],AX  
0A84:0222 1156FE         ADC       WORD PTR [BP-02],DX  
0A84:0225 8B46FC         MOV       AX,WORD PTR [BP-04]  
0A84:0228 8B56FE         MOV       DX,WORD PTR [BP-02]  
0A84:022B B107           MOV       CL,07  
0A84:022D D1E0           SHL       AX,1  
0A84:022F D1D2           RCL       DX,1  
0A84:0231 FEC9           DEC       CL  
0A84:0233 75F8           JNZ       022D  
0A84:0235 8B4EFC         MOV       CX,WORD PTR [BP-04]  
0A84:0238 8B5EFE         MOV       BX,WORD PTR [BP-02]  
0A84:023B 8BF1           MOV       SI,CX  
0A84:023D B119           MOV       CL,19  
0A84:023F D1EB           SHR       BX,1  
0A84:0241 D1DE           RCR       SI,1  
0A84:0243 FEC9           DEC       CL  
0A84:0245 75F8           JNZ       023F  
0A84:0247 0BC6           OR        AX,SI  
0A84:0249 0BD3           OR        DX,BX  
0A84:024B 8946FC         MOV       WORD PTR [BP-04],AX  
0A84:024E 8956FE         MOV       WORD PTR [BP-02],DX  
0A84:0251 8B46F8         MOV       AX,WORD PTR [BP-08]  
0A84:0254 8B56FA         MOV       DX,WORD PTR [BP-06]  
0A84:0257 0146FC         ADD       WORD PTR [BP-04],AX  
0A84:025A 1156FE         ADC       WORD PTR [BP-02],DX  
0A84:025D 3346F4         XOR       AX,WORD PTR [BP-0C]  
0A84:0260 3356F6         XOR       DX,WORD PTR [BP-0A]  
0A84:0263 2346FC         AND       AX,WORD PTR [BP-04]  
0A84:0266 2356FE         AND       DX,WORD PTR [BP-02]  
0A84:0269 3346F4         XOR       AX,WORD PTR [BP-0C]  
0A84:026C 3356F6         XOR       DX,WORD PTR [BP-0A]

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-08-05 at 18:50:25ID23624380
Tags

Intel Assembly x86

Topics

Assembly Programming Language

,

Algorithms

,

C Programming Language

Participating Experts
3
Points
500
Comments
13

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. script interpreter?
    Hi, I need to use c++ to write a simple script interpreter (not a compiler). The program takes a file as input, and parse it. Right now I only need to support nested iternation for loops . Any souce code will be more than welcomed.
  2. Postscript Interpreter
    Hello I am lumped with a project I think is a bit out of my scope. However I would still like to give it a good shot. I want to design a Postscript Interpreter. Nothing fancy, even for a subset of the language will do (Just to get the theory of it down). The problem is, and...
  3. vb compiler or interpreter
    what do vb uses compiler or interpreter...i hope at the time of development...uses interpreter and then we compile it to an application...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: BdLmPosted on 2008-08-06 at 01:27:45ID: 22168109

you are manipulating an array:
 see http://support.microsoft.com/kb/104644/eng

 

by: Infinity08Posted on 2008-08-06 at 01:29:59ID: 22168120

A direct translation to C-like code would look something like :

0A84:0210 8B5E06         MOV       BX,WORD PTR [BP+06]   ; BX = arg
0A84:0213 0307           ADD       AX,WORD PTR [BX]      ; DX:AX = *BX
0A84:0215 135702         ADC       DX,WORD PTR [BX+02]   ;/
0A84:0218 2D885B         SUB       AX,5B88               ; DX:AX -= 0x28955B88
0A84:021B 81DA9528       SBB       DX,2895               ;/
0A84:021F 0146FC         ADD       WORD PTR [BP-04],AX   ; loc1 += DX:AX
0A84:0222 1156FE         ADC       WORD PTR [BP-02],DX   ;/
0A84:0225 8B46FC         MOV       AX,WORD PTR [BP-04]   ; DX:AX = loc1
0A84:0228 8B56FE         MOV       DX,WORD PTR [BP-02]   ;/
0A84:022B B107           MOV       CL,07                 ; DX:AX <<= 7
0A84:022D D1E0           SHL       AX,1                  ;|
0A84:022F D1D2           RCL       DX,1                  ;|
0A84:0231 FEC9           DEC       CL                    ;|
0A84:0233 75F8           JNZ       022D                  ;/
0A84:0235 8B4EFC         MOV       CX,WORD PTR [BP-04]   ; BX:CX = loc1
0A84:0238 8B5EFE         MOV       BX,WORD PTR [BP-02]   ;/
0A84:023B 8BF1           MOV       SI,CX                 ; SI = CX
0A84:023D B119           MOV       CL,19                 ; BX:SI >>= 25
0A84:023F D1EB           SHR       BX,1                  ;|
0A84:0241 D1DE           RCR       SI,1                  ;|
0A84:0243 FEC9           DEC       CL                    ;|
0A84:0245 75F8           JNZ       023F                  ;/
0A84:0247 0BC6           OR        AX,SI                 ; DX:AX |= BX:SI
0A84:0249 0BD3           OR        DX,BX                 ;/
0A84:024B 8946FC         MOV       WORD PTR [BP-04],AX   ; loc1 = DX:AX
0A84:024E 8956FE         MOV       WORD PTR [BP-02],DX   ;/
0A84:0251 8B46F8         MOV       AX,WORD PTR [BP-08]   ; DX:AX = loc2
0A84:0254 8B56FA         MOV       DX,WORD PTR [BP-06]   ;/
0A84:0257 0146FC         ADD       WORD PTR [BP-04],AX   ; loc1 += DX:AX
0A84:025A 1156FE         ADC       WORD PTR [BP-02],DX   ;/
0A84:025D 3346F4         XOR       AX,WORD PTR [BP-0C]   ; DX:AX ^= loc3
0A84:0260 3356F6         XOR       DX,WORD PTR [BP-0A]   ;/
0A84:0263 2346FC         AND       AX,WORD PTR [BP-04]   ; DX:AX &= loc1
0A84:0266 2356FE         AND       DX,WORD PTR [BP-02]   ;/
0A84:0269 3346F4         XOR       AX,WORD PTR [BP-0C]   ; DX:AX ^= loc3
0A84:026C 3356F6         XOR       DX,WORD PTR [BP-0A]   ;/
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:

Select allOpen in new window

 

by: Infinity08Posted on 2008-08-06 at 01:32:28ID: 22168131

Note that the code is incomplete (i. something is missing before and after). The arg is a function argument (most likely) which is a pointer to a 32bit value, and the loc1, loc2 and loc3 are local 32bit variables to the function.

A more high-level interpretation of the assembler would be something like :

loc1 += *arg - 0x28955B88
loc1 = (loc1 << 7) | (loc1 >> 25)
DX:AX = ((loc2 ^ loc3) & (loc1 + loc2)) ^ loc3

                                              
1:
2:
3:

Select allOpen in new window

 

by: thydzikPosted on 2008-08-06 at 01:35:19ID: 22168146

thanks for the reply. I know it is manipulating 2 strings, but I just can't seem to work out what it is doing to them.
and why the constants 5B88 and 2895.

 

by: Infinity08Posted on 2008-08-06 at 01:41:13ID: 22168170

Could this be some kind of encryption/encoding ?

Where does this code come from ?

Can you show the entire function ?

 

by: thydzikPosted on 2008-08-06 at 01:58:25ID: 22168240

thanks for response infinity, was hoping you would respond

yes, it is a form of encoding I am trying to reverse engineer.
very new to assembly, can understand all the functions line by line, but now struggling to understand what this group is trying to achieve.

I didn't want to include too much code, as it would be a bit too much for the points. But I shall include some more, the code repeats itself about 20 times, moving to the next word each time.

[bx] is the location of the string to be encoded
[bp] is the location of the encoded

I shall get back to you on your high-level interpretation after I fully understand it.

0A84:0210 8B5E06         MOV       BX,WORD PTR [BP+06]  
0A84:0213 0307           ADD       AX,WORD PTR [BX]  
0A84:0215 135702         ADC       DX,WORD PTR [BX+02]  
0A84:0218 2D885B         SUB       AX,5B88  
0A84:021B 81DA9528       SBB       DX,2895  
0A84:021F 0146FC         ADD       WORD PTR [BP-04],AX  
0A84:0222 1156FE         ADC       WORD PTR [BP-02],DX  
0A84:0225 8B46FC         MOV       AX,WORD PTR [BP-04]  
0A84:0228 8B56FE         MOV       DX,WORD PTR [BP-02]  
0A84:022B B107           MOV       CL,07  
0A84:022D D1E0           SHL       AX,1  
0A84:022F D1D2           RCL       DX,1  
0A84:0231 FEC9           DEC       CL  
0A84:0233 75F8           JNZ       022D  
0A84:0235 8B4EFC         MOV       CX,WORD PTR [BP-04]  
0A84:0238 8B5EFE         MOV       BX,WORD PTR [BP-02]  
0A84:023B 8BF1           MOV       SI,CX  
0A84:023D B119           MOV       CL,19  
0A84:023F D1EB           SHR       BX,1  
0A84:0241 D1DE           RCR       SI,1  
0A84:0243 FEC9           DEC       CL  
0A84:0245 75F8           JNZ       023F  
0A84:0247 0BC6           OR        AX,SI  
0A84:0249 0BD3           OR        DX,BX  
0A84:024B 8946FC         MOV       WORD PTR [BP-04],AX  
0A84:024E 8956FE         MOV       WORD PTR [BP-02],DX  
0A84:0251 8B46F8         MOV       AX,WORD PTR [BP-08]  
0A84:0254 8B56FA         MOV       DX,WORD PTR [BP-06]  
0A84:0257 0146FC         ADD       WORD PTR [BP-04],AX  
0A84:025A 1156FE         ADC       WORD PTR [BP-02],DX  
0A84:025D 3346F4         XOR       AX,WORD PTR [BP-0C]  
0A84:0260 3356F6         XOR       DX,WORD PTR [BP-0A]  
0A84:0263 2346FC         AND       AX,WORD PTR [BP-04]  
0A84:0266 2356FE         AND       DX,WORD PTR [BP-02]  
0A84:0269 3346F4         XOR       AX,WORD PTR [BP-0C]  
0A84:026C 3356F6         XOR       DX,WORD PTR [BP-0A]  
0A84:026F 8B5E06         MOV       BX,WORD PTR [BP+06]  
0A84:0272 034704         ADD       AX,WORD PTR [BX+04]  
0A84:0275 135706         ADC       DX,WORD PTR [BX+06]  
0A84:0278 2DAA48         SUB       AX,48AA  
0A84:027B 81DA3817       SBB       DX,1738  
0A84:027F 0146F0         ADD       WORD PTR [BP-10],AX  
0A84:0282 1156F2         ADC       WORD PTR [BP-0E],DX  
0A84:0285 8B46F0         MOV       AX,WORD PTR [BP-10]  
0A84:0288 8B56F2         MOV       DX,WORD PTR [BP-0E]  
0A84:028B B10C           MOV       CL,0C  
0A84:028D D1E0           SHL       AX,1  
0A84:028F D1D2           RCL       DX,1  
0A84:0291 FEC9           DEC       CL  
0A84:0293 75F8           JNZ       028D  
0A84:0295 8B4EF0         MOV       CX,WORD PTR [BP-10]  
0A84:0298 8B5EF2         MOV       BX,WORD PTR [BP-0E]  
0A84:029B 8BF1           MOV       SI,CX  
0A84:029D B114           MOV       CL,14  
0A84:029F D1EB           SHR       BX,1  
0A84:02A1 D1DE           RCR       SI,1  
0A84:02A3 FEC9           DEC       CL  
0A84:02A5 75F8           JNZ       029F  
0A84:02A7 0BC6           OR        AX,SI  
0A84:02A9 0BD3           OR        DX,BX  
0A84:02AB 8946F0         MOV       WORD PTR [BP-10],AX  
0A84:02AE 8956F2         MOV       WORD PTR [BP-0E],DX  
0A84:02B1 8B46FC         MOV       AX,WORD PTR [BP-04]  
0A84:02B4 8B56FE         MOV       DX,WORD PTR [BP-02]  
0A84:02B7 0146F0         ADD       WORD PTR [BP-10],AX  
0A84:02BA 1156F2         ADC       WORD PTR [BP-0E],DX  
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:

Select allOpen in new window

 

by: Infinity08Posted on 2008-08-06 at 03:53:27ID: 22168785

>> the code repeats itself about 20 times, moving to the next word each time.

ok.

The part of code you posted would be something like this in high level :

tmp = DX:AX;                                    /* carry */
loc1 += (tmp + arg[0]) - 0x28955B88;            /* subtract key ? */
loc1 = (loc1 << 7) | (loc1 >> 25);              /* rotate left over 7 bits */
tmp = ((loc2 ^ loc3) & (loc1 + loc2)) ^ loc3;   /* carry */
loc1 += loc2;
loc4 += (tmp + arg[1]) - 0x173848AA;            /* subtract key ? */
loc4 = (loc4 << 12) | (loc4 >> 20);             /* rotate left over 12 bits */
tmp = loc1;                                     /* carry (incomplete ?) */
loc4 += loc1;

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:

Select allOpen in new window

 

by: thydzikPosted on 2008-08-06 at 16:43:58ID: 22176338

PaulCaswell,

this is not a crack attempt, but simply reverse engineering a program.
In this case I have both the input and output and want to determine how it gets from one to the other.

 

by: DanRollinsPosted on 2008-08-06 at 19:37:13ID: 22176994

It does look like it might be an encryption sequence.  It applies a constantly-changing value (based on previously calculated value) to each 32-bit value in sequence.  This is what I called a "scrambler" in a simple (pre-CryptoAPI) tool I wrote.   It makes it difficult to see a pattern match between the input and the output.

It's also interesting to see that it was written for execution on a 16-bit CPU.  Sequences like...

   0A84:0213 0307           ADD       AX,WORD PTR [BX]  
   0A84:0215 135702      ADC       DX,WORD PTR [BX+02]  

... only make sense in that environment.  My guess is that this is some legacy code from some long-forgotten library.  As it undoubtedly uses trap-door logic (for instance, the XOR sequences) it would be difficult, if not impossible, to discern the algorithm based on only the input and output.  Or to determine the input based only on the output and the algorithm.

Assuming this is an encryption algorithm, about the only reason I know of to be looking at code like this would be to attempt to write a crack.. figure out how to get past some sort of security wall.  

 

by: thydzikPosted on 2008-08-06 at 20:32:51ID: 22177180

Infinity,

Thanks for the info, I can understand up to line 25.
But could you please help me understand what lines 25 to 36
what are the XORs achieving?

 

by: BdLmPosted on 2008-08-06 at 22:57:36ID: 22178205

XOR is used in many crypto algo's because of the symmetry, that means to can use XOR functions for crpyt and encrypt data,
eg. have a look at the http://de.wikipedia.org/wiki/Advanced_Encryption_Standard and you will see the XOR in the AES.

 

by: thydzikPosted on 2008-08-07 at 02:48:56ID: 31484241

Thanks all, points allocated to Infinity08 for the simplification of the code.
and BdLm, for given me something to further research.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...