모델 무결성 검증

업데이트: 2023/05/25

이 페이지는 Cubism 4.2 이하의 구 버전용입니다. 최신 페이지는 여기

Cubism SDK는 모델을 로드하기 전에 변조에 의해 모델에 잘못된 데이터가 포함되어 있지 않은지 검증할 수 있습니다.

불특정한 MOC3 파일이 읽어 들여질 것으로 예상되는 경우 csmInitializeModelInPlace로 csmMoc의 오브젝트를 생성하기 전에, 읽어 들이는 MOC3 파일의 무결성을 확인하는 것을 권장합니다.
단, 무결성 검증은 성능에 영향을 줄 가능성이 있으므로 주의하십시오.

모델의 무결성을 검증하려면 Cubism Core의 csmHasMocConsistency()(SDK for Java는 Live2DCubismCore.hasMocConsistency())를 사용합니다.
자세한 내용은 「Cubism Core API 참조」를 참조하십시오.

Cubism SDK for Native의 CubismMoc::Create(), Cubism SDK for Web의 CubismMoc.create() 및 Cubism SDK for Java의 CubismMoc.create()는 모델을 로드할 때 MOC3 파일의 무결성을 검증합니다.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// Cubism SDK for Native
CubismMoc* CubismMoc::Create(const csmByte* mocBytes, csmSizeInt size, csmBool shouldCheckMocConsistency)
{
CubismMoc* cubismMoc = NULL;
void* alignedBuffer = CSM_MALLOC_ALLIGNED(size, Core::csmAlignofMoc);
memcpy(alignedBuffer, mocBytes, size);
if (shouldCheckMocConsistency)
{
// .moc3의 무결성 확인
csmBool consistency = HasMocConsistency(alignedBuffer, size);
if (!consistency)
{
CSM_FREE_ALLIGNED(alignedBuffer);
// 무결성을 확인할 수 없으면 처리하지 않음
CubismLogError("Inconsistent MOC3.");
return cubismMoc;
}
}
...
return cubismMoc;
}
// Cubism SDK for Native CubismMoc* CubismMoc::Create(const csmByte* mocBytes, csmSizeInt size, csmBool shouldCheckMocConsistency) { CubismMoc* cubismMoc = NULL; void* alignedBuffer = CSM_MALLOC_ALLIGNED(size, Core::csmAlignofMoc); memcpy(alignedBuffer, mocBytes, size); if (shouldCheckMocConsistency) { // .moc3의 무결성 확인 csmBool consistency = HasMocConsistency(alignedBuffer, size); if (!consistency) { CSM_FREE_ALLIGNED(alignedBuffer); // 무결성을 확인할 수 없으면 처리하지 않음 CubismLogError("Inconsistent MOC3."); return cubismMoc; } } ... return cubismMoc; }
// Cubism SDK for Native

CubismMoc* CubismMoc::Create(const csmByte* mocBytes, csmSizeInt size, csmBool shouldCheckMocConsistency)
{
    CubismMoc* cubismMoc = NULL;

    void* alignedBuffer = CSM_MALLOC_ALLIGNED(size, Core::csmAlignofMoc);
    memcpy(alignedBuffer, mocBytes, size);

    if (shouldCheckMocConsistency)
    {
        // .moc3의 무결성 확인
        csmBool consistency = HasMocConsistency(alignedBuffer, size);
        if (!consistency)
        {
            CSM_FREE_ALLIGNED(alignedBuffer);

            // 무결성을 확인할 수 없으면 처리하지 않음
            CubismLogError("Inconsistent MOC3.");
            return cubismMoc;
        }
    }

    ...

    return cubismMoc;
}
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// Cubism SDK for Web
public static create(
mocBytes: ArrayBuffer,
shouldCheckMocConsistency: boolean
): CubismMoc {
let cubismMoc: CubismMoc = null;
if (shouldCheckMocConsistency) {
// .moc3의 무결성 확인
const consistency = this.hasMocConsistency(mocBytes);
if (!consistency) {
// 무결성을 확인할 수 없으면 처리하지 않음
CubismLogError(`Inconsistent MOC3.`);
return cubismMoc;
}
}
...
return cubismMoc;
}
// Cubism SDK for Web public static create( mocBytes: ArrayBuffer, shouldCheckMocConsistency: boolean ): CubismMoc { let cubismMoc: CubismMoc = null; if (shouldCheckMocConsistency) { // .moc3의 무결성 확인 const consistency = this.hasMocConsistency(mocBytes); if (!consistency) { // 무결성을 확인할 수 없으면 처리하지 않음 CubismLogError(`Inconsistent MOC3.`); return cubismMoc; } } ... return cubismMoc; }
// Cubism SDK for Web

  public static create(
    mocBytes: ArrayBuffer,
    shouldCheckMocConsistency: boolean
  ): CubismMoc {
    let cubismMoc: CubismMoc = null;

    if (shouldCheckMocConsistency) {
      // .moc3의 무결성 확인
      const consistency = this.hasMocConsistency(mocBytes);

      if (!consistency) {
        // 무결성을 확인할 수 없으면 처리하지 않음
        CubismLogError(`Inconsistent MOC3.`);
        return cubismMoc;
      }
    }

    ...

    return cubismMoc;
  }
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// Cubism SDK for Java
public static CubismMoc create(byte[] mocBytes, boolean shouldCheckMocConsistency) {
com.live2d.sdk.cubism.core.CubismMoc moc;
if (mocBytes == null) {
return null;
}
if (shouldCheckMocConsistency) {
// .moc3의 무결성을 확인.
boolean consistency = hasMocConsistency(mocBytes);
if (!consistency) {
CubismDebug.cubismLogError("Inconsistent MOC3.");
return null;
}
}
...
return cubismMoc;
}
// Cubism SDK for Java public static CubismMoc create(byte[] mocBytes, boolean shouldCheckMocConsistency) { com.live2d.sdk.cubism.core.CubismMoc moc; if (mocBytes == null) { return null; } if (shouldCheckMocConsistency) { // .moc3의 무결성을 확인. boolean consistency = hasMocConsistency(mocBytes); if (!consistency) { CubismDebug.cubismLogError("Inconsistent MOC3."); return null; } } ... return cubismMoc; }
// Cubism SDK for Java

    public static CubismMoc create(byte[] mocBytes, boolean shouldCheckMocConsistency) {
        com.live2d.sdk.cubism.core.CubismMoc moc;

        if (mocBytes == null) {
            return null;
        }

        if (shouldCheckMocConsistency) {
            // .moc3의 무결성을 확인.
            boolean consistency = hasMocConsistency(mocBytes);

            if (!consistency) {
                CubismDebug.cubismLogError("Inconsistent MOC3.");
                return null;
            }
        }

        ...

        return cubismMoc;
    }


Cubism SDK의 샘플에서는 디폴트로 로드 시에 무결성 검증을 실시하고 있지만, 이쪽은 임의로 무효화할 수 있습니다.

모델을 불러올 때 무결성 검증을 무효화하려면 SDK for Native의 LAppDefine::MocConsistencyValidationEnable, SDK for Web의 LAppDefine.MOCConsistencyValidationEnable 및 SDK for Java의 LAppDefine.MOC_CONSISTENCY_VALIDATION_ENABLE의 값을 변경합니다.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// Cubism SDK for Native
// MOC3 무결성 검증 옵션
const csmBool MocConsistencyValidationEnable = true;
// Cubism SDK for Native // MOC3 무결성 검증 옵션 const csmBool MocConsistencyValidationEnable = true;
// Cubism SDK for Native

    // MOC3 무결성 검증 옵션
    const csmBool MocConsistencyValidationEnable = true;
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// Cubism SDK for Web
// MOC3 일관성 검증 옵션
export const MOCConsistencyValidationEnable = true;
// Cubism SDK for Web // MOC3 일관성 검증 옵션 export const MOCConsistencyValidationEnable = true;
// Cubism SDK for Web

// MOC3 일관성 검증 옵션
export const MOCConsistencyValidationEnable = true;
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// Cubism SDK for Java
/**
※MOC3의 무결성을 검증할지 여부. 유효하다면 true.
*/
public static final boolean MOC_CONSISTENCY_VALIDATION_ENABLE = true;
// Cubism SDK for Java /** ※MOC3의 무결성을 검증할지 여부. 유효하다면 true. */ public static final boolean MOC_CONSISTENCY_VALIDATION_ENABLE = true;
// Cubism SDK for Java

    /**
     ※MOC3의 무결성을 검증할지 여부. 유효하다면 true.
     */
    public static final boolean MOC_CONSISTENCY_VALIDATION_ENABLE = true;


Unity도 마찬가지로 기본적으로는 CubismMoc.CreateFrom()으로 모델을 가져올 때 무결성을 검증합니다.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
// Cubism SDK for Unity
public static CubismMoc CreateFrom(byte[] moc3, bool shouldCheckMocConsistency = true)
{
if (shouldCheckMocConsistency && !HasMocConsistency(moc3))
{
Debug.LogError("This Moc3 is Invalid. This model generation process is aborted and prefab is not created.");
return null;
}
var moc = CreateInstance<CubismMoc>();
moc.Bytes = moc3;
return moc;
}
// Cubism SDK for Unity public static CubismMoc CreateFrom(byte[] moc3, bool shouldCheckMocConsistency = true) { if (shouldCheckMocConsistency && !HasMocConsistency(moc3)) { Debug.LogError("This Moc3 is Invalid. This model generation process is aborted and prefab is not created."); return null; } var moc = CreateInstance<CubismMoc>(); moc.Bytes = moc3; return moc; }
// Cubism SDK for Unity

public static CubismMoc CreateFrom(byte[] moc3, bool shouldCheckMocConsistency = true)
{
    if (shouldCheckMocConsistency && !HasMocConsistency(moc3))
    {
        Debug.LogError("This Moc3 is Invalid. This model generation process is aborted and prefab is not created.");
        return null;
    }

    var moc = CreateInstance<CubismMoc>();


    moc.Bytes = moc3;


    return moc;
}

이 기사가 도움이 되었나요?
아니요
이 기사에 관한 의견 및 요청사항을 보내 주시기 바랍니다.