LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-18-2013, 04:17 PM   #1
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Rep: Reputation: 55
How can I un XOR encode a file?


How can I un XOR encode a file?

When I try with C I get a file that can't be read by objdump:
Code:
        
        buf = malloc(size);

        fread(buf, 1, size, f);

        for (i = 0; i < size; i++) {
                buf[i] ^= 0x81;
        }
Code:
$ objdump -DR output2
objdump: output2: File format not recognized
I can still strings that file and get more info but I'm trying to view the assembly code.
 
Old 03-18-2013, 04:29 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Just run xor again on the output from the first time.

xor is reflexive - doing it a second time reverses what was done the first time.
 
Old 03-18-2013, 04:42 PM   #3
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Original Poster
Rep: Reputation: 55
Quote:
Originally Posted by jpollard View Post
Just run xor again on the output from the first time.

xor is reflexive - doing it a second time reverses what was done the first time.
That's what I did in C, but it appears the whole program is not XOR, which I am assuming is why objdump can't read it.

This would be the decode routine to the compiler I'm assuming:
Code:
     
    xor    %eax,%eax
    lea    0x0(%esi,%eiz,1),%esi
    xorb   $0x81,0x138(%eax,%ebx,1)
  
    add    $0x1,%eax
    cmp    $0x1ed,%eax

Last edited by abefroman; 03-18-2013 at 04:48 PM.
 
Old 03-23-2013, 07:03 AM   #4
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by abefroman View Post
That's what I did in C, but it appears the whole program is not XOR, which I am assuming is why objdump can't read it.
You are incorrectly assuming that 'buf' always contains 'size' bytes, where in fact it only contains the number of bytes that have been reported to be read by fread() --- which you failed to check. I would recommend something similar to:
Code:
const size_t MAX_BUF_SZ = 1024;

char* buf = malloc(MAX_BUF_SZ);
size_t bytesRead = 0;

while ((bytesRead = fread(buf, 1, MAX_BUF_SZ, f)) > 0)
{
    for (size_t i = 0; i < bytesRead; ++i)
    {
        buf[i] ^= 0x81;
    }

    // ... (write bytesRead number of bytes from buf to other file)
}
As for objdump not recognizing your file, well there's good reason... the file should be pure data with no discernible format to disassemble.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
speex speexenc does not encode an audio file felipe1982 Linux - Software 5 06-30-2010 10:26 AM
[SOLVED] C xor encryption strength madsovenielsen Linux - Security 5 06-15-2010 01:58 AM
GPG - encode file while manipulating output file name itmozart Linux - Newbie 2 10-03-2009 12:28 PM
encode text file anhtt Solaris / OpenSolaris 8 04-03-2008 12:03 AM
Absence of XOR in C++, flaw or streamlined? xadrith Programming 6 11-10-2007 05:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration