Code Monkey home page Code Monkey logo

Comments (4)

devttys0 avatar devttys0 commented on July 18, 2024

Thanks, just updated the signatures!

For extraction, binwalk can carve out the ELSP sections, but it relies on external utilities for performing things like decompression or specific file type handling. Alternatively, you could write a binwalk plugin to handle extraction of specific file types or signatures.

Also, to answer your offline question regarding obfuscated length fields, libmagic doesn't provide any way of handling those AFAIK. Binwalk's math keyword extension would almost work, but not quite; it'd probably be easiest to write a binwalk plugin to handle this.

On a quasi-related note, do you know if lancom released any GPL code, specifically for any SquasFS modifications they may have made? At least for the LC-831A, they appear to be using a non-standard SquashFS format.

from binwalk.

christophvw avatar christophvw commented on July 18, 2024

No, they did not release any.
The data in the ELSP sections is not compressed, and when it is there are complete archives inside which can be extracted as they are.

from binwalk.

christophvw avatar christophvw commented on July 18, 2024

They use YAFFS2, maybe the SquashFS is from the 3rd party modem Firmware?

from binwalk.

christophvw avatar christophvw commented on July 18, 2024
#include "standard-types.hsl"

#pragma displayname("LANCOM Firmware") ;
#pragma fileextensions(".upx")

#pragma byteorder(big_endian) 

typedef struct LancomFwHeader
{
#pragma lockAt(0)
    WORD CheckSum;
    CHAR ProjectName[48];
    DWORD LoadAddress;
    DWORD OffsetToNextChunk;
    DWORD Unknown;

    struct Signature
    {
        UBYTE ChunkHdr1; /* E */
        UBYTE ChunkHdr2; /* L */
        UBYTE ChunkHdr3; /* S */
        UBYTE ChunkHdr4; /* F/S/P/O */
        __verify(ChunkHdr1 == 0x45);
        __verify(ChunkHdr2 == 0x4c);
        __verify(ChunkHdr3 == 0x53);
    };

    UBYTE Unknown1[8];
 
    /* 
        253   alpha
        255   Rel
        220   PR
        <220  RC x
        >220 && < 237 RU x-220 
    */
    UBYTE ReleaseNumber;
    UBYTE BuildDate[2];

    UBYTE HasValidBuildNumber;
    __verify(HasValidBuildNumber == 0);
    WORD BuildNumber;

    CHAR  Version[4];
    CHAR  DeviceName[36];
    BYTE  Unknown2[8];
    blob  Data[(((OffsetToNextChunk % 0xFC00) & 0x3FF) ? ((OffsetToNextChunk % 0xFC00) | 0x3FF) + 1 : 0) + ((505 * (OffsetToNextChunk / 0xFC00) + ((((OffsetToNextChunk % 0xFC00) & 0x3FF) ? ((OffsetToNextChunk % 0xFC00) | 0x3FF) + 1 : 0) != 0)) << 7)];
} LANCOMFWHEADER;


typedef struct LancomFwHeaderOld
{
#pragma lockAt(0)
    WORD CheckSum;
    CHAR ProjectName[48];
    DWORD LoadAddress;
    DWORD OffsetToNextChunk;
    DWORD Unknown;

    struct Signature
    {
        UBYTE ChunkHdr1; /* E */
        UBYTE ChunkHdr2; /* L */
        UBYTE ChunkHdr3; /* S */
        UBYTE ChunkHdr4; /* F/S/P/O */
        __verify(ChunkHdr1 == 0x45);
        __verify(ChunkHdr2 == 0x4c);
        __verify(ChunkHdr3 == 0x53);
    };

    UBYTE Unknown3[3];
    CHAR  BuildDate[8];
    CHAR  Locale[3];
    CHAR  Version[4];
    CHAR  DeviceName[36];
    BYTE  Unknown5[8];
    blob  Data[(((OffsetToNextChunk % 0xFC00) & 0x3FF) ? ((OffsetToNextChunk % 0xFC00) | 0x3FF) + 1 : 0) + ((505 * (OffsetToNextChunk / 0xFC00) + ((((OffsetToNextChunk % 0xFC00) & 0x3FF) ? ((OffsetToNextChunk % 0xFC00) | 0x3FF) + 1 : 0) != 0)) << 7)];
} LANCOMFWHEADER_OLD;

function AutoParseLancomFirmware
{
    UDWord NextHeaderOffset = 0;
    UDWord OffsetPosition = 54;
    UDWord HeaderSize = 128;
    UDWord OffsetPart1;
    UDWord OffsetPart2;
    
    /* Insert first structure @ offset 0 */
    if (__getUByteAt(77) != 0)
    {
        __addStructureAt(NextHeaderOffset, "LancomFwHeaderOld", "");
    }
    else
    {
        __addStructureAt(NextHeaderOffset, "LancomFwHeader", "");
    };
    
    /* calculate the offset of the next chunk */
    UDWord OffsetToNextChunk = __getUDWordAt(NextHeaderOffset + OffsetPosition);
    OffsetPart1 = OffsetToNextChunk / 0xFC00;
    OffsetPart2 = OffsetToNextChunk % 0xFC00;
    if ( OffsetPart2 & 0x3FF )
        OffsetPart2 = (OffsetPart2 | 0x3FF) + 1;
    OffsetToNextChunk = OffsetPart2 + ((505 * OffsetPart1 + (OffsetPart2 != 0)) << 7);
    
    while ((NextHeaderOffset + HeaderSize + OffsetToNextChunk) < __getDocSize())
    {
        NextHeaderOffset += HeaderSize + OffsetToNextChunk;
        if (__getUByteAt(77) != 0)
        {
            __addStructureAt(NextHeaderOffset, "LancomFwHeaderOld", "");
        }
        else
        {
            __addStructureAt(NextHeaderOffset, "LancomFwHeader", "");
        };
        OffsetToNextChunk = __getUDWordAt(NextHeaderOffset + OffsetPosition);

        OffsetPart1 = OffsetToNextChunk / 0xFC00;
        OffsetPart2 = OffsetToNextChunk % 0xFC00;
        if ( OffsetPart2 & 0x3FF )
            OffsetPart2 = (OffsetPart2 | 0x3FF) + 1;
        OffsetToNextChunk = OffsetPart2 + ((505 * OffsetPart1 + (OffsetPart2 != 0)) << 7);
    };
}

from binwalk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.