Skip to content

Commit

Permalink
AdvmpTest项目上传&其他更新
Browse files Browse the repository at this point in the history
  • Loading branch information
zylc369 committed Apr 3, 2015
1 parent 8045c91 commit 151b3a4
Show file tree
Hide file tree
Showing 43 changed files with 3,966 additions and 21 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ $RECYCLE.BIN/
# IntelliJ IDEA
*.iml

#Maven
# Maven
target
target/*

# current project
AdvmpTest/obj
AdvmpTest/libs
AdvmpTest/bin
AdvmpTest/bin/project.properties
AdvmpTest/bin/proguard-project.txt

# =========================
# Operating System Files
# =========================
Expand Down
26 changes: 26 additions & 0 deletions AdvmpTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="buwai.android.shell.advmptest"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="10" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Binary file added AdvmpTest/ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions AdvmpTest/jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(call all-subdir-makefiles)
23 changes: 23 additions & 0 deletions AdvmpTest/jni/advmpc/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

DEVFLAG := _static

LOCAL_MODULE := advmpc

LOCAL_C_INCLUDES += $(LOCAL_PATH)/../minizip

LOCAL_SRC_FILES := ioapi.c \
unzip.c \
Globals.cpp \
avmp.cpp \
BitConvert.cpp \
InterpC.cpp \
io.cpp \
Utils.cpp \
YcFile.cpp \

LOCAL_LDLIBS := -llog -lz

include $(BUILD_SHARED_LIBRARY)
14 changes: 14 additions & 0 deletions AdvmpTest/jni/advmpc/BitConvert.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "stdafx.h"
#include "BitConvert.h"

// 将字节数组转换为字符串。
char* ToString(unsigned char bytes[], size_t size) {
char* str = (char*) calloc (size + 1, sizeof(char));
if (NULL == str) {
return NULL;
}
for (int i = 0; i < size; i++) {
str[i] = (char)(bytes[i]);
}
return str;
}
8 changes: 8 additions & 0 deletions AdvmpTest/jni/advmpc/BitConvert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

/**
* 将字节数组转换为字符串。
* @return 成功:返回字符串。失败:返回NULL。
* @note 返回指针值需要调用者释放。
*/
char* ToString(unsigned char bytes[], size_t size);
13 changes: 13 additions & 0 deletions AdvmpTest/jni/advmpc/Globals.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "Globals.h"

ADVMPGlobals gAdvmp;

#ifdef _AVMP_DEBUG_

const char* gYcFileName = "classes.yc";

#else

//+${gYcFileName}

#endif // _DEBUG_
16 changes: 16 additions & 0 deletions AdvmpTest/jni/advmpc/Globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <jni.h>
#include "YcFile.h"

// TODO 这里是调试标志。
#define _AVMP_DEBUG_

extern const char* gYcFileName;

typedef struct _ADVMPGlobals {
YcFile* ycFile;
char* ycFilePath;
} ADVMPGlobals;

extern ADVMPGlobals gAdvmp;
3 changes: 3 additions & 0 deletions AdvmpTest/jni/advmpc/InterpC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "InterpC.h"


5 changes: 5 additions & 0 deletions AdvmpTest/jni/advmpc/InterpC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <jni.h>

jvalue BWdvmInterpretPortable();
6 changes: 6 additions & 0 deletions AdvmpTest/jni/advmpc/Utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "stdafx.h"
#include "Utils.h"

char* GetAppPath(JNIEnv* env) {

}
8 changes: 8 additions & 0 deletions AdvmpTest/jni/advmpc/Utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

/**
* 获得APP文件路径。
* @param[in] env JNI环境。
* @return 返回APP文件路径。这个路径使用完后需要通过free函数释放内存。
*/
char* GetAppPath(JNIEnv* env);
174 changes: 174 additions & 0 deletions AdvmpTest/jni/advmpc/YcFile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#include "stdafx.h"
#include "BitConvert.h"
#include "io.h"
#include "Globals.h"
#include "unzip.h"
#include "YcFile.h"

YcFile::YcFile(const char* filePath)
: mFilePath(NULL)
{
mFilePath = strdup(filePath);
}

YcFile::~YcFile() {
if (NULL != mFilePath) {
free(mFilePath);
}
}

// 解析Yc文件。
bool YcFile::parse() {
FileReader fileReader;

if (!fileReader.Open(mFilePath)) {
MY_LOG_WARNING("打开文件\"%s\"失败。errno:%d-%s.", mFilePath, errno, strerror(errno));
return false;
}


unsigned char* buffer = new unsigned char[6];
if (!fileReader.ReadBytes(buffer, 6)) {
delete[] buffer;
return false;
}

// 校验魔术字。
char* magic = ToString(buffer, 6);
if (0 != strcmp(magic, MAGIC)) {
MY_LOG_WARNING("魔术字校验失败。");
delete[] buffer;
free(magic);
return false;
}
free(magic);
delete[] buffer;

mYcFormat.header.magic = MAGIC;

if (!fileReader.ReadUInt(&mYcFormat.header.methodSize)) {
MY_LOG_WARNING("读取方法结构个数失败。");
return false;
}

if (!fileReader.ReadUInt(&mYcFormat.header.methodOffset)) {
MY_LOG_WARNING("读取方法段偏移失败。");
return false;
}

if (!fileReader.ReadUInt(&mYcFormat.header.separatorDataSize)) {
MY_LOG_WARNING("读取抽离数组size失败。");
return false;
}

if (!fileReader.ReadUInt(&mYcFormat.header.separatorDataOffset)) {
MY_LOG_WARNING("读取抽离数据段偏移失败。");
return false;
}

// TODO 这里先不解析AdvmpMethod的数据。

unsigned int separatorDataSize = mYcFormat.header.separatorDataSize;
// 解析抽离数据。
if (0 != separatorDataSize) {
mYcFormat.separatorDatas = new SeparatorData*[separatorDataSize];
if (!fileReader.Seek(mYcFormat.header.separatorDataOffset)) {
MY_LOG_WARNING("设置文件指针位置失败。");
return false;
}

for (int i = 0; i < separatorDataSize; i++) {
mYcFormat.separatorDatas[i] = (SeparatorData*) calloc(1, sizeof(SeparatorData));
if (!fileReader.ReadUInt(&mYcFormat.separatorDatas[i]->methodIndex)) {
MY_LOG_WARNING("%d. 读取SeparatorData中方法索引失败。", i);
return false;
}
if (!fileReader.ReadUInt(&mYcFormat.separatorDatas[i]->instSize)) {
MY_LOG_WARNING("%d. 读取SeparatorData中方法指令size失败。", i);
return false;
}
mYcFormat.separatorDatas[i]->insts = new unsigned short[mYcFormat.separatorDatas[i]->instSize];
if (!fileReader.ReadUShorts(mYcFormat.separatorDatas[i]->insts, mYcFormat.separatorDatas[i]->instSize)) {
MY_LOG_WARNING("%d. 读取SeparatorData中方法指令size失败。", i);
return false;
}
}
}

return true;
}

//////////////////////////////////////////////////////////////////////////
//

YcFormat::YcFormat()
: methods(NULL), separatorDatas(NULL)
{
memset(&header, 0, sizeof(YcHeader));
}

YcFormat::~YcFormat() {
if (NULL != methods) {
unsigned int size = header.methodSize;
for (int i = 0; i < size; i++) {
free(methods[i]);
}
delete[] methods;
}
if (NULL != separatorDatas) {
unsigned int size = header.separatorDataSize;
for (int i = 0; i < size; i++) {
if (NULL != separatorDatas[i]->insts) {
delete[] separatorDatas[i]->insts;
}
free(separatorDatas[i]);
}
delete[] separatorDatas;
}
}

//////////////////////////////////////////////////////////////////////////

// 打开并解析yc文件。
bool OpenAndParseYc(JNIEnv* env) {
YcFile* ycFile = new YcFile(gAdvmp.ycFilePath);
if (ycFile->parse()) {
gAdvmp.ycFile = ycFile;
} else {
MY_LOG_ERROR("打开&解析yc文件失败!");
return false;
}
}

//////////////////////////////////////////////////////////////////////////

// 释放Yc文件。
uLong ReleaseYcFile(const char* filePath, unsigned char* buffer) {
MY_LOG_INFO("zip文件:%s", filePath);
ZipReader zipReader(filePath);
if (!zipReader.Open()) {
MY_LOG_WARNING("打开zip文件失败:%s", filePath);
return false;
}

char* filePathInZip = (char*) calloc(strlen(gYcFileName) + strlen("assets") + 1, sizeof(char));
uLong fileSize = zipReader.GetFileSizeInZip(filePathInZip);

uLong bRet = 0;
if (0 == fileSize) {
goto _ret;
}

buffer = (unsigned char*) calloc(sizeof(unsigned char), fileSize);
if (!zipReader.ReadBytes(filePathInZip, buffer, fileSize)) {
goto _ret;
}

bRet = fileSize;

_ret:
if (NULL != filePathInZip) {
free(filePathInZip);
}
return bRet;
}
Loading

0 comments on commit 151b3a4

Please sign in to comment.