Author Topic: How DNA works  (Read 4963 times)

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
How DNA works
« on: November 27, 2007, 05:38:42 AM »
I'm going to write evolved DNA deobfuscator, and it is essential to understand perfectly how DNA works. Please check, if my explanation is precise.
http://www.darwinbots.com/WikiManual/index...her_Explanation

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7715
    • View Profile
How DNA works
« Reply #1 on: November 27, 2007, 09:38:02 AM »
For 2.43 it looks correct.  However, with recent changes to the way DNA is handled, it changes things slightly.  Conditions can now be executed inside the body of genes.

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
How DNA works
« Reply #2 on: November 27, 2007, 09:45:42 AM »
Hmmm... When has this change been applied? Because trunk has:
Code: [Select]
      Case 5 'conditions
        If CurrentFlow = COND Then
          ExecuteConditions .DNA(a).value
        End If
      Case 6 'logic commands (and, or, etc.)
        If CurrentFlow = COND Then
          ExecuteLogic .DNA(a).value
        End If
Or is it 2.43 on the trunk? Where can I see the latest source then?

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7715
    • View Profile
How DNA works
« Reply #3 on: November 27, 2007, 09:58:59 AM »
Eric hasn't released the latest source since 2.43.  There's some sensitive information in it, too, so I'm not sure how or when we're going to release it generally.  But I'm sure Eric'll be kind enough to copy+paste the relevant code here.

Also, Eric hasn't been using the SVN, so I'm not sure what version I have in there

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
How DNA works
« Reply #4 on: November 27, 2007, 10:10:51 AM »
Code: [Select]
    
       Case 5 'conditions
        'EricL  11/2007 New execution paradym.  Conditions can now be executeed anywhere in the gene
        If CurrentFlow = COND Or CurrentFlow = body Or CurrentFlow = ELSEBODY Then
          ExecuteConditions .DNA(a).value
        End If
      Case 6 'logic commands (and, or, etc.)
        'EricL  11/2007 New execution paradym.  Conditions can now be executeed anywhere in the gene
        If CurrentFlow = COND Or CurrentFlow = body Or CurrentFlow = ELSEBODY Then
          ExecuteLogic .DNA(a).value
        End If
      Case 7 'store, inc and dec
        If CurrentFlow = body Or CurrentFlow = ELSEBODY Then
          If CondStateIsTrue Then  ' Check the Bool stack.  If empty or True on top, do the stores.  Don't if False.
            ExecuteStores .DNA(a).value
            If n = robfocus Or Not (rob(n).console Is Nothing) Then rob(n).ga(currgene) = True  'EricL  This gene fired this cycle!  Populate ga()
          End If
        End If


I'll post the sorce less the password information for 2.43t later today.
« Last Edit: November 27, 2007, 10:12:13 AM by EricL »
Many beers....

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
How DNA works
« Reply #5 on: November 27, 2007, 10:27:22 AM »
Eric, thanks a lot! Would you please also post ExecuteFlowCommands function's source?

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
How DNA works
« Reply #6 on: November 27, 2007, 10:30:22 AM »
"The memory and both integer and boolean stacks are persistent during a single cycle. It means, that if you leave a value in a stack in one gene, it will be still there when you enter the next gene. "

This is not strictly correct for the boolean stack.  As you say, there are no implicit operators on the integer stack.  It takes explicit DNA commands to push and pop from the stack and gene boundaries do not have implicit meaning other than marking the boundaries of non-coding regions within which push and pop operations are ignroed.

But gene boundaries implicitly operate on the boolean stack.   A cond statement clears the boolean stack for example (a clear stack is implicitly true).  A start statement is an implicit AND of all arguments on the boolean stack.



Code: [Select]
Private Function ExecuteFlowCommands(n As Integer) As Boolean
'returns true if a stop command was found (start, stop, or else)
'returns false if cond was found
  ExecuteFlowCommands = False
  Select Case n
    Case 1 'cond
      CurrentFlow = COND
      ' Clear the boolean stack
      Condst.pos = 0
      Condst.val(0) = 0
      Exit Function
    Case 2, 3, 4 'assume a stop command, or it really is a stop command
      'this is supposed to come before case 2 and 3, since these commands
      'must be executed before start and else have a chance to go
      ExecuteFlowCommands = True
      If CurrentFlow = COND Then CurrentCondFlag = AddupCond
      CurrentFlow = CLEAR
      Select Case n
        Case 2 'start
          If CurrentCondFlag = NEXTBODY Then CurrentFlow = body
          currgene = currgene + 1
        Case 3 'else
          If CurrentCondFlag = NEXTELSE Then CurrentFlow = ELSEBODY
          currgene = currgene + 1
      End Select
  End Select
End Function
Many beers....

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
How DNA works
« Reply #7 on: November 27, 2007, 10:33:02 AM »
Quote from: EricL
Code: [Select]
    
      Case 7 'store, inc and dec
        If CurrentFlow = body Or CurrentFlow = ELSEBODY Then
          If CondStateIsTrue Then  ' Check the Bool stack.  If empty or True on top, do the stores.  Don't if False.
            ExecuteStores .DNA(a).value
            If n = robfocus Or Not (rob(n).console Is Nothing) Then rob(n).ga(currgene) = True  'EricL  This gene fired this cycle!  Populate ga()
          End If
        End If
WOW! Does it mean, that
Code: [Select]
*.nrg 20000 > 50 .repro store now works as expected?

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
How DNA works
« Reply #8 on: November 27, 2007, 10:37:36 AM »
Quote from: Gobo
WOW! Does it mean, that
Code: [Select]
*.nrg 20000 > 50 .repro store now works as expected?
Yes, exactly.  Check out this topic.
Many beers....

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
How DNA works
« Reply #9 on: November 27, 2007, 10:40:35 AM »
Quote from: EricL
But gene boundaries implicitly operate on the boolean stack.   A cond statement clears the boolean stack for example (a clear stack is implicitly true).  A start statement is an implicit AND of all arguments on the boolean stack.
Yep, I noticed it already and changed that para. Though it needs to be rewritten again taking into account the cutting edge wisdom

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
How DNA works
« Reply #10 on: November 27, 2007, 10:47:18 AM »
Quote from: EricL
Yes, exactly.  Check out this topic.
Cool! I think, it means I can make Sanger do if-then-else blocks without limitations!

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
How DNA works
« Reply #11 on: November 27, 2007, 10:58:28 AM »
Quote from: Gobo
Cool! I think, it means I can make Sanger do if-then-else blocks without limitations!
Indeed, I think that it does too.
Many beers....

Offline Sprotiel

  • Bot Destroyer
  • ***
  • Posts: 135
    • View Profile
How DNA works
« Reply #12 on: December 01, 2007, 09:05:40 AM »
I made a partly-functioning DNA deobfuscator about a year ago, in Python. Obviously, it used 2.43 syntax and is now obsolete, but I'll try to see if it can be updated. If there's any way I can help you, Gobo, please ask.

Offline Gobo

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
How DNA works
« Reply #13 on: December 01, 2007, 02:02:33 PM »
Quote from: Sprotiel
I made a partly-functioning DNA deobfuscator about a year ago, in Python. Obviously, it used 2.43 syntax and is now obsolete, but I'll try to see if it can be updated. If there's any way I can help you, Gobo, please ask.
Sure, would you share your code? I speak Pythonese a bit
« Last Edit: December 01, 2007, 02:03:06 PM by Gobo »

Offline Sprotiel

  • Bot Destroyer
  • ***
  • Posts: 135
    • View Profile
How DNA works
« Reply #14 on: December 02, 2007, 12:58:21 PM »
Quote from: Gobo
Sure, would you share your code?
Certainly. Here it is.